y
y
yq
Search…
y
y
yq
v4.x
yq
How It Works
Upgrading from V3
Commands
Evaluate
Evaluate All
Shell Completion
Operators
Add
Alternative (Default value)
Anchor and Alias Operators
Assign (Update)
Boolean Operators
Collect into Array
Column
Comment Operators
Compare Operators
Contains
Create, Collect into Object
Date Time
Delete
Document Index
Encode / Decode
Entries
Env Variable Operators
Equals
Eval
File Operators
Flatten
Group By
Has
Keys
Length
Line
Load
Map
Multiply (Merge)
Parent
Path
Pick
Pipe
Recursive Descent (Glob)
Reduce
Reverse
Select
Sort
Sort Keys
Split into Documents
String Operators
Style
Subtract
Tag
Traverse (Read)
Union
Unique
Variable Operators
With
Usage
Output format
Working with CSV, TSV
Working with JSON
Working with Properties
Working with XML
Front Matter
Split into multiple files
GitHub Action
Tips, Tricks, Troubleshooting
Github Page
Powered By
GitBook
Document Index
Use the
documentIndex
operator (or the
di
shorthand) to select nodes of a particular document.
Note that versions prior to 4.18 require the 'eval/e' command to be specified.
yq e <exp> <file>
Retrieve a document index
Given a sample.yml file of:
1
a
:
cat
2
---
3
a
:
frog
Copied!
then
1
yq
'.a | document_index'
sample.yml
Copied!
will output
1
0
2
---
3
1
Copied!
Retrieve a document index, shorthand
Given a sample.yml file of:
1
a
:
cat
2
---
3
a
:
frog
Copied!
then
1
yq
'.a | di'
sample.yml
Copied!
will output
1
0
2
---
3
1
Copied!
Filter by document index
Given a sample.yml file of:
1
a
:
cat
2
---
3
a
:
frog
Copied!
then
1
yq
'select(document_index == 1)'
sample.yml
Copied!
will output
1
a
:
frog
Copied!
Filter by document index shorthand
Given a sample.yml file of:
1
a
:
cat
2
---
3
a
:
frog
Copied!
then
1
yq
'select(di == 1)'
sample.yml
Copied!
will output
1
a
:
frog
Copied!
Print Document Index with matches
Given a sample.yml file of:
1
a
:
cat
2
---
3
a
:
frog
Copied!
then
1
yq
'.a | ({"match": ., "doc": document_index})'
sample.yml
Copied!
will output
1
match
:
cat
2
doc
:
0
3
match
:
frog
4
doc
:
1
Copied!
Previous
Delete
Next
Encode / Decode
Last modified
4mo ago
Copy link
Contents
Retrieve a document index
Retrieve a document index, shorthand
Filter by document index
Filter by document index shorthand
Print Document Index with matches