How do I get scalars from nested yaml structures? #2448
Unanswered
GrabCAD-Gary
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've been trying all day to pull the values from keys that have them in a file like this in bash:
That is, I want to get the keys and values for
rp1
andrp2
from block1/root and forgp1
andgp2
from block1/level1, etc. According to the yaml docs that means I want to skip the seqs and map labels and get the scalar vales from inside the maps. I used your snippet to print a comment next to each entry and that says these entries are scalars. I've tried everything from here that looked like it might help and a myriad other things without success. I can get the entries:with
yq -r '.block1.parameters | to_entries[].value'
but then
yq
won't split them because it says they're maps or a slew of other reasons, depending on the code. Dumping them shows that the entire stringkey: value
seems to have been grabbed as a key (single value) and not as a key/value pair. My goal is to set some vars based on these keys and values. I've tried the tips and recipes here for getting arrays and setting env. var.s. That doesn't work here apparently because of the nesting. I've tried so many things I've lost track of them all. It appears that this would be achievable if I had justkey: value
entries at the root level but I can't get the nested pairs. This is as close as I've got. Could someone please show me how to do this?I should point out that the contents of such a file will be unknown so I'm looking to iterate and find the right entries without knowledge of the keys. In case that wasn't obvious Pulling a single entry by name or all entries I can do.
Also, if you could point me to some docs that explain the notation for dots, double dots, brackets, etc. that'd help immensely. I can't find any explanation of those things here anywhere. The operator docs use them but there's no explanation that I can find.
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions