Skip to content

How do I select multiple keys for output? #1898

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

You must be logged in to vote

Sorry didn't see all the attention here, @tony-sol you can do it like this:

yq '.[] |= pick(["name", "status"])' data1.yaml

Explanation:

  • You want to pick particular fields from each map in the array
  • .[] |= <exp> will match each element in the array, and update that element w.r.t itself
  • pick([]) will take a given map and pick fields (omitting the rest)

See https://mikefarah.gitbook.io/yq/operators/pick for details.

The different with doing .[] | (.name, .status) is that will match all elements and just pulling out just those values.

Replies: 15 comments

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
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
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
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
0 replies
Comment options

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

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
8 participants
Converted from issue

This discussion was converted from issue #287 on December 10, 2023 22:47.