return a key at different level that matches a value #252
-
foo:
bar:
stat: spam-$ANCHOR
baz:
stat: beef-$ANCHOR
qaz:
stat: ham I am interested in a selector which will return all keys in the n'th (0<=n<=2) level for which I can relax the question by switching contains in matches and providing exact value for the selector matcher. I.e. return all keys in the n'th level for which I could only came up with a selector that returns me the key which has the match but not any level above it. For example: echo '
foo:
bar:
stat: anchor1
baz:
stat: anchor2
qaz:
stat: ham
' | dasel -p yaml -m '.(?:stat=anchor1).-'
stat Which returned |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
This can't be done at the moment. I've considered a Theoretically it can be done but it would be a fairly large job because of the way each node is currently built. |
Beta Was this translation helpful? Give feedback.
-
Hey @foolioo, With dasel v2 (still in development but at a good point) you can achieve this with: $ echo '
foo:
bar:
stat: anchor1
baz:
stat: anchor2
qaz:
stat: ham
' | dasel -r yaml 'foo.all().filter(or(equal(stat,anchor1),equal(stat,anchor2))).key()'
bar
baz Does this satisfy your needs? I'm looking for a few good examples for the documentation and README info for updating to v2. If you would be interested in running the development version of v2 let me know. I'm keen to ensure all prior functionality is still possible. The documentation can be found here: https://daseldocs.tomwright.me/v/v2/ |
Beta Was this translation helpful? Give feedback.
This can't be done at the moment. I've considered a
^
parent selector before to traverse back up the tree but haven't looked in to how it might be achieved.Theoretically it can be done but it would be a fairly large job because of the way each node is currently built.