Skip to content

Unable to index array #1432

Answered by mikefarah
s-pravin asked this question in Q&A
Nov 14, 2022 · 4 comments · 1 reply
Discussion options

You must be logged in to vote

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.

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@s-pravin
Comment options

Answer selected by s-pravin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants