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
  • Pivot a sequence of sequences
  • Pivot sequence of heterogeneous sequences
  • Pivot sequence of maps
  • Pivot sequence of heterogeneous maps

Was this helpful?

  1. Operators

Pivot

Emulates the PIVOT function supported by several popular RDBMS systems.

Pivot a sequence of sequences

Given a sample.yml file of:

- - foo
  - bar
  - baz
- - sis
  - boom
  - bah

then

yq 'pivot' sample.yml

will output

- - foo
  - sis
- - bar
  - boom
- - baz
  - bah

Pivot sequence of heterogeneous sequences

Missing values are "padded" to null.

Given a sample.yml file of:

- - foo
  - bar
  - baz
- - sis
  - boom
  - bah
  - blah

then

yq 'pivot' sample.yml

will output

- - foo
  - sis
- - bar
  - boom
- - baz
  - bah
- -
  - blah

Pivot sequence of maps

Given a sample.yml file of:

- foo: a
  bar: b
  baz: c
- foo: x
  bar: y
  baz: z

then

yq 'pivot' sample.yml

will output

foo:
  - a
  - x
bar:
  - b
  - y
baz:
  - c
  - z

Pivot sequence of heterogeneous maps

Missing values are "padded" to null.

Given a sample.yml file of:

- foo: a
  bar: b
  baz: c
- foo: x
  bar: y
  baz: z
  what: ever

then

yq 'pivot' sample.yml

will output

foo:
  - a
  - x
bar:
  - b
  - y
baz:
  - c
  - z
what:
  -
  - ever
PreviousPipeNextRecursive Descent (Glob)

Last updated 10 months ago

Was this helpful?