Delete
Deletes matching entries in maps or arrays.
Delete entry in map
Given a sample.yml file of:
a: cat
b: dogthen
yq 'del(.b)' sample.ymlwill output
a: catDelete nested entry in map
Given a sample.yml file of:
a:
a1: fred
a2: froodthen
yq 'del(.a.a1)' sample.ymlwill output
a:
a2: froodDelete entry in array
Given a sample.yml file of:
- 1
- 2
- 3then
yq 'del(.[1])' sample.ymlwill output
- 1
- 3Delete nested entry in array
Given a sample.yml file of:
- a: cat
b: dogthen
yq 'del(.[0].a)' sample.ymlwill output
- b: dogDelete no matches
Given a sample.yml file of:
a: cat
b: dogthen
yq 'del(.c)' sample.ymlwill output
a: cat
b: dogDelete matching entries
Given a sample.yml file of:
a: cat
b: dog
c: batthen
yq 'del( .[] | select(. == "*at") )' sample.ymlwill output
b: dogRecursively delete matching keys
Given a sample.yml file of:
a:
name: frog
b:
name: blog
age: 12then
yq 'del(.. | select(has("name")).name)' sample.ymlwill output
a:
b:
age: 12Last updated
Was this helpful?