How do I select multiple keys for output? #1898
-
This seems like a basic question but I can't find examples anywhere in the documentation.
And I want to select only the beta and delta keys, so that I get the following output:
How do I do it? Every example in the documentation is only selecting a single key. The equivalent in
or
|
Beta Was this translation helpful? Give feedback.
Replies: 15 comments
-
This can't be done yet - would be neat though :) |
Beta Was this translation helpful? Give feedback.
-
Would be great to document that this feature is missing. I wasted a lot of time trying to figure it out. |
Beta Was this translation helpful? Give feedback.
-
hey, is this available now? i have a use case for exactly this, and wasted a lot of time to figure out how to do this |
Beta Was this translation helpful? Give feedback.
-
Yeah cool - sorry for your time wasted - I'd love to add this at some stage but for now I'll add it to the readme as a known missing feature |
Beta Was this translation helpful? Give feedback.
-
Super, i would like to take a stab at it |
Beta Was this translation helpful? Give feedback.
-
Cool - I've been thinking about it, there are other related issues about being able to:
And I think they all can be solved by refactoring the code that handles path expressions as an array into a proper path expression tree. This will allow multiple keys for output by an expression like Other commands (like write) use the same code, so they too will benefit by being able to give complex expressions to update.. I don't think it will be easy though... |
Beta Was this translation helpful? Give feedback.
-
https://www.geeksforgeeks.org/expression-tree/ for reference.
|
Beta Was this translation helpful? Give feedback.
-
Might take it on myself actually - it's so fundamental to the whole codebase. Sorry - normally I definitely welcome help, but this is a significant bit if work that affects the core |
Beta Was this translation helpful? Give feedback.
-
cool, no worries. Will wait for you to add these functionalities |
Beta Was this translation helpful? Give feedback.
-
How does one search for multiple keys? The docs and help doesn't offer a clue. |
Beta Was this translation helpful? Give feedback.
-
Adding this in posterity for those who also couldn't seem to locate this in the docs. Surrounding the desired keys in parens for example, with foobar.yaml:
|
Beta Was this translation helpful? Give feedback.
-
Is there a way to save objects structure and sequence? - name: foo
status: waiting
a-lot-of-other: fields
- name: bar
status: waiting
a-lot-of-other: fields And i want to get just - name: foo
status: waiting
- name: bar
status: waiting I've tried foo
bar
waiting
waiting UPD: for anyone else, who will searching for this - looks like using |
Beta Was this translation helpful? Give feedback.
-
I got it working without using a map. Just use
|
Beta Was this translation helpful? Give feedback.
-
Sorry didn't see all the attention here, @tony-sol you can do it like this:
Explanation:
See https://mikefarah.gitbook.io/yq/operators/pick for details. The different with doing |
Beta Was this translation helpful? Give feedback.
-
Moved to discussion - so github tells me when there's activity here :) |
Beta Was this translation helpful? Give feedback.
Sorry didn't see all the attention here, @tony-sol you can do it like this:
Explanation:
.[] |= <exp>
will match each element in the array, and update that element w.r.t itselfSee 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.