Extract all entries that contain value in array #1288
Answered
by
mikefarah
julianbarg
asked this question in
Q&A
-
Given an array:
How do I extract all entries that contain "c", i.e. the entries "foo" and "bar". What if these entries were nested on an arbitrary deeper level, i.e. selecting on "nested2" containing "target" in the following array:
|
Beta Was this translation helpful? Give feedback.
Answered by
mikefarah
Jul 31, 2022
Replies: 2 comments
-
First example: yq '.[] | select(.[] == "c")' examples/data1.yaml Explanation:
second example: yq '.[] | select(.. == "foo")' examples/data1.yaml Explanation:
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... |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
julianbarg
-
Good stuff! This is exactly the output I had this output in mind. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First example:
yq '.[] | select(.[] == "c")' examples/data1.yaml
Explanation:
.[]
select(.[] == "c")
second example:
yq '.[] | select(.. == "foo")' examples/data1.yaml
Explanation:
.[]
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...