Skip to content

Extract all entries that contain value in array #1288

Answered by mikefarah
julianbarg asked this question in Q&A
Discussion options

You must be logged in to vote

First example:

yq '.[] | select(.[] == "c")' examples/data1.yaml

Explanation:

  • expand the top level entries .[]
  • select the ones that have a (direct) child == "foo": select(.[] == "c")

second example:

yq '.[] | select(.. == "foo")' examples/data1.yaml

Explanation:

  • expand the top level entries .[]
  • select the ones that have a any child == "foo": select(.. == "c") (recursively checks the tree)

Not sure which output is desired - this is outputting the child values of the nodes. You could pipe it through 'key' to get the key node...

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by julianbarg
Comment options

You must be logged in to vote
1 reply
@dominicshields
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants