y
y
yq
Search…
Line
Returns the line of the matching node. Starts from 1, 0 indicates there was no line data.
Note that versions prior to 4.18 require the 'eval/e' command to be specified.
yq e <exp> <file>

Returns line of value node

Given a sample.yml file of:
1
a: cat
2
b:
3
c: cat
Copied!
then
1
yq '.b | line' sample.yml
Copied!
will output
1
3
Copied!

Returns line of key node

Pipe through the key operator to get the line of the key
Given a sample.yml file of:
1
a: cat
2
b:
3
c: cat
Copied!
then
1
yq '.b | key| line' sample.yml
Copied!
will output
1
2
Copied!

First line is 1

Given a sample.yml file of:
1
a: cat
Copied!
then
1
yq '.a | line' sample.yml
Copied!
will output
1
1
Copied!

No line data is 0

Running
1
yq --null-input '{"a": "new entry"} | line'
Copied!
will output
1
0
Copied!
Last modified 2mo ago