yq/pkg/yqlib/doc/Delete Operator.md
2020-11-19 22:11:26 +11:00

723 B

Deletes matching entries in maps or arrays.

Examples

Delete entry in map

Given a sample.yml file of:

a: cat
b: dog

then

yq eval 'del(.b)' sample.yml

will output

a: cat

Delete entry in array

Given a sample.yml file of:

- 1
- 2
- 3

then

yq eval 'del(.[1])' sample.yml

will output

- 1
- 3

Delete no matches

Given a sample.yml file of:

a: cat
b: dog

then

yq eval 'del(.c)' sample.yml

will output

a: cat
b: dog

Delete matching entries

Given a sample.yml file of:

a: cat
b: dog
c: bat

then

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

will output

b: dog