Trying to get the value of an object that is up the path from a searched-for array element value #2080
Replies: 3 comments
-
I figured out a way to do this, but it's probably not the most elegant. I get the path of where the matching element was found and read that into an array. I then use the values from the array to create the path to the
|
Beta Was this translation helpful? Give feedback.
-
This was a little tricky:
Explanation:
|
Beta Was this translation helpful? Give feedback.
-
It's been over a year, but I found this page again while I was seeking a cleaner answer than what I had originally come up with. @mikefarah I hadn't seen the answer that you posted in June of 2024 until now. Thank you for finding a clean way to do this, and for the explanation. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I've tried several variations of commands to do this, but all without success. I tried to get chatGPT to assist me, but it's so bad with yq that it's almost laughable. There is some underlying concept here that eludes me. I've tried using
contains
andselect
andhas
and piping topath
etc. but I'm just not getting it. Help would really be appreciated!Here is the top part of the actual file that I'm working with. In the last
pages
array there is an element with a value that contains "general-ledger.statistical-account.yaml" My script gets that value as input (or the equivalent from another element), so that's what I have to search with. What I'd like to be able to find is the value of thegroup
object above that array element, which in this example is "General Ledger". I just can't put the yq pieces together in the right way to make that happen.Beta Was this translation helpful? Give feedback.
All reactions