Select

Select is used to filter arrays and maps by a boolean expression.

  • equals / not equals (==, !=) operators here

  • comparison (>=, < etc) operators here

  • boolean operators (and, or, any etc) here

Select elements from array using wildcard prefix

Given a sample.yml file of:

- cat
- goat
- dog

then

yq '.[] | select(. == "*at")' sample.yml

will output

cat
goat

Select elements from array using wildcard suffix

Given a sample.yml file of:

then

will output

Select elements from array using wildcard prefix and suffix

Given a sample.yml file of:

then

will output

Select elements from array with regular expression

See more regular expression examples under the string operator docs.

Given a sample.yml file of:

then

will output

Select items from a map

Given a sample.yml file of:

then

will output

Use select and with_entries to filter map keys

Given a sample.yml file of:

then

will output

Select multiple items in a map and update

Note the brackets around the entire LHS.

Given a sample.yml file of:

then

will output

Last updated

Was this helpful?