yq
v4.x
v4.x
  • yq
  • How It Works
  • Recipes
  • Upgrading from V3
  • Commands
    • Evaluate
    • Evaluate All
    • Shell Completion
  • Operators
    • Add
    • Alternative (Default value)
    • Anchor and Alias Operators
    • Array to Map
    • Assign (Update)
    • Boolean Operators
    • Collect into Array
    • Column
    • Comment Operators
    • Compare Operators
    • Contains
    • Create, Collect into Object
    • Date Time
    • Delete
    • Divide
    • Document Index
    • Encode / Decode
    • Entries
    • Env Variable Operators
    • Equals
    • Eval
    • File Operators
    • Filter Operator
    • Flatten
    • Group By
    • Has
    • Keys
    • Kind
    • Length
    • Line
    • Load
    • Min
    • Map
    • Max
    • Modulo
    • Multiply (Merge)
    • Omit
    • Parent
    • Path
    • Pick
    • Pipe
    • Pivot
    • Recursive Descent (Glob)
    • Reduce
    • Reverse
    • Select
    • Shuffle
    • Slice Array
    • Sort
    • Sort Keys
    • Split into Documents
    • String Operators
    • Style
    • Subtract
    • Tag
    • To Number
    • Traverse (Read)
    • Union
    • Unique
    • Variable Operators
    • With
  • Usage
    • Output format
    • Working with CSV, TSV
    • Working with JSON
    • Working with Properties
    • Working with XML
    • Working with LUA
    • Working with TOML
    • Working with Shell Output
    • Front Matter
    • Split into multiple files
    • GitHub Action
    • Tips, Tricks, Troubleshooting
  • Github Page
Powered by GitBook
On this page
  • Delete entry in map
  • Delete nested entry in map
  • Delete entry in array
  • Delete nested entry in array
  • Delete no matches
  • Delete matching entries
  • Recursively delete matching keys

Was this helpful?

  1. Operators

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
PreviousDate TimeNextDivide

Last updated 2 years ago

Was this helpful?