yq/pkg/yqlib/doc/operators/delete.md
2022-10-25 12:47:13 +11:00

1.3 KiB

Delete

Deletes matching entries in maps or arrays.

Delete entry in map

Given a sample.yml file of:

a: cat
b: dog

then

yq 'del(.b)' sample.yml

will output

a: cat

Delete nested entry in map

Given a sample.yml file of:

a:
  a1: fred
  a2: frood

then

yq 'del(.a.a1)' sample.yml

will output

a:
  a2: frood

Delete entry in array

Given a sample.yml file of:

- 1
- 2
- 3

then

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

will output

- 1
- 3

Delete nested entry in array

Given a sample.yml file of:

- a: cat
  b: dog

then

yq 'del(.[0].a)' sample.yml

will output

- b: dog

Delete no matches

Given a sample.yml file of:

a: cat
b: dog

then

yq '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 'del( .[] | select(. == "*at") )' sample.yml

will output

b: dog

Recursively delete matching keys

Given a sample.yml file of:

a:
  name: frog
  b:
    name: blog
    age: 12

then

yq 'del(.. | select(has("name")).name)' sample.yml

will output

a:
  b:
    age: 12