yq
v3.x
v3.x
  • yq
  • Upgrading from V2
  • Commands
    • Read
    • Validate
    • Compare
    • Write
    • Create
    • Delete
    • Merge
    • Prefix
    • Shell Completion
  • Usage
    • Output format
    • Path Expressions
    • Value Parsing
    • Working with JSON
  • Github Page
Powered by GitBook
On this page
  • Prefix a document
  • Updating files in-place
  • Multiple Documents
  • Prefix a single document
  • Prefix all documents

Was this helpful?

  1. Commands

Prefix

Prefixes a yaml document with the given path expression. The complete yaml content will be nested inside the new prefix path.

PreviousMergeNextShell Completion

Last updated 5 years ago

Was this helpful?

yq p <yaml_file> <path>

See docs for for more details.

Prefix a document

Given a data1.yaml file of:

a:
  b: [1, 2]

then

yq p data1.yaml c.d

will output:

c:
  d:
    a:
      b: [1, 2]

Updating files in-place

yq p -i data1.yaml c

will update the data1.yaml file so that the path 'c' prefixes the document.

Multiple Documents

Prefix a single document

Given a data1.yaml file of:

something: else
---
a: simple
b: cat

then

yq p -d1 data1.yaml c

will output:

something: else
---
c:
  a: simple
  b: cat

Prefix all documents

Given a data1.yaml file of:

something: else
---
a: simple
b: cat

then

yq p -d'*' data1.yaml c

will output:

c:
  something: else
---
c:
  a: simple
  b: cat
path expression