y
y
yq
Search…
Compare Operators
Comparison operators (>, >=, <, <=) can be used for comparing scalar values of the same time.
The following types are currently supported:
  • numbers
  • strings
  • datetimes

Related Operators

  • equals / not equals (==, !=) operators here
  • boolean operators (and, or, any etc) here
  • select operator here
Note that versions prior to 4.18 require the 'eval/e' command to be specified.
yq e <exp> <file>

Compare numbers (>)

Given a sample.yml file of:
1
a: 5
2
b: 4
Copied!
then
1
yq '.a > .b' sample.yml
Copied!
will output
1
true
Copied!

Compare equal numbers (>=)

Given a sample.yml file of:
1
a: 5
2
b: 5
Copied!
then
1
yq '.a >= .b' sample.yml
Copied!
will output
1
true
Copied!

Compare strings

Compares strings by their bytecode.
Given a sample.yml file of:
1
a: zoo
2
b: apple
Copied!
then
1
yq '.a > .b' sample.yml
Copied!
will output
1
true
Copied!

Compare date times

You can compare date times. Assumes RFC3339 date time format, see date-time operators for more information.
Given a sample.yml file of:
1
a: 2021-01-01T03:10:00Z
2
b: 2020-01-01T03:10:00Z
Copied!
then
1
yq '.a > .b' sample.yml
Copied!
will output
1
true
Copied!

Both sides are null: > is false

Running
1
yq --null-input '.a > .b'
Copied!
will output
1
false
Copied!

Both sides are null: >= is true

Running
1
yq --null-input '.a >= .b'
Copied!
will output
1
true
Copied!