Delete
yq d <yaml_file|json_file> <path_to_delete>
This command can take a json file as input too, and will output yaml unless specified to export as json (-j)
To Stdout¶
Given a sample.yaml file of:
b:
  c: 2
  apples: green
then
yq d sample.yaml b.c
will output:
b:
  apples: green
From STDIN¶
cat sample.yaml | yq d - b.c
Deleting array elements¶
Given a sample.yaml file of:
b:
  c: 
    - 1
    - 2
    - 3
then
yq d sample.yaml 'b.c[1]'
will output:
b:
  c:
  - 1
  - 3
Deleting nodes in-place¶
Given a sample.yaml file of:
b:
  c: 2
  apples: green
then
yq d -i sample.yaml b.c
will update the sample.yaml file so that the 'c' node is deleted
Keys with dots¶
When specifying a key that has a dot use key lookup indicator.
b:
  foo.bar: 7
yaml r sample.yaml 'b[foo.bar]'
yaml w sample.yaml 'b[foo.bar]' 9
Any valid yaml key can be specified as part of a key lookup.
Note that the path is in quotes to avoid the square brackets being interpreted by your shell.