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
Unique
This is used to filter out duplicated items in an array. Note that the original order of the array is maintained.
Note that versions prior to 4.18 require the 'eval/e' command to be specified.
yq e <exp> <file>
Unique array of scalars (string/numbers)
Note that unique maintains the original order of the array.
Given a sample.yml file of:
1
-
2
2
-
1
3
-
3
4
-
2
Copied!
then
1
yq
'unique'
sample.yml
Copied!
will output
1
-
2
2
-
1
3
-
3
Copied!
Unique nulls
Unique works on the node value, so it considers different representations of nulls to be different
Given a sample.yml file of:
1
-
~
2
-
null
3
-
~
4
-
null
Copied!
then
1
yq
'unique'
sample.yml
Copied!
will output
1
-
~
2
-
null
Copied!
Unique all nulls
Run against the node tag to unique all the nulls
Given a sample.yml file of:
1
-
~
2
-
null
3
-
~
4
-
null
Copied!
then
1
yq
'unique_by(tag)'
sample.yml
Copied!
will output
1
-
~
Copied!
Unique array object fields
Given a sample.yml file of:
1
-
name
:
harry
2
pet
:
cat
3
-
name
:
billy
4
pet
:
dog
5
-
name
:
harry
6
pet
:
dog
Copied!
then
1
yq
'unique_by(.name)'
sample.yml
Copied!
will output
1
-
name
:
harry
2
pet
:
cat
3
-
name
:
billy
4
pet
:
dog
Copied!
Previous
Union
Next
Variable Operators
Last modified
1mo ago
Copy link
Contents
Unique array of scalars (string/numbers)
Unique nulls
Unique all nulls
Unique array object fields