Extract all entries that contain value in array #1288
-
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.
Replies: 2 comments 1 reply
-
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.
-
Good stuff! This is exactly the output I had this output in mind. |
Beta Was this translation helpful? Give feedback.
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...