-
I have a sample YAML file with following content:
Trying to get first occurrence of
My expectation is that it shall output array index 0 i.e. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Any suggestions? |
Beta Was this translation helpful? Give feedback.
-
You were very close:
|
Beta Was this translation helpful? Give feedback.
-
Here's the output I get:
I would like to get CL33 as output. |
Beta Was this translation helpful? Give feedback.
-
Oh my apologies: yq '[.status.interfaces[] | select(.deviceID == "123d")][0] | .name' file.yaml Basically after splatting the array with |
Beta Was this translation helpful? Give feedback.
Oh my apologies:
yq '[.status.interfaces[] | select(.deviceID == "123d")][0] | .name' file.yaml
Basically after splatting the array with
[]
you need to put the matches back into an array by surrounding the expression with[ ... ]
- then you can index the first one.