example_a:
- key: sa01
name: sa
match_a:
sa_key: sa01
This one works:
yq '.example_a[] |select(.key == "sa01")'
Is it possible to make it work this way:
yq '.example_a[] |select(.key == .match_a.sa_key)'
Yes, that's possible using a variable on the key:
yq '.match_a.sa_key as $key | .example_a[] |select(.key == $key)' i.yaml
So we save .match_a.sa_key
as the var $key
, so that we can use that in the select()
directly
Output:
key: sa01
name: sa