y
y
yq
Search…
Select
Select is used to filter arrays and maps by a boolean expression.

Select elements from array

Given a sample.yml file of:
1
- cat
2
- goat
3
- dog
Copied!
then
1
yq eval '.[] | select(. == "*at")' sample.yml
Copied!
will output
1
cat
2
goat
Copied!

Select and update matching values in map

Given a sample.yml file of:
1
a:
2
things: cat
3
bob: goat
4
horse: dog
Copied!
then
1
yq eval '(.a.[] | select(. == "*at")) |= "rabbit"' sample.yml
Copied!
will output
1
a:
2
things: rabbit
3
bob: rabbit
4
horse: dog
Copied!