mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-06 18:24:57 +08:00
Added support for more comparison ops
This commit is contained in:
@@ -10,6 +10,12 @@ The `or` and `and` operators take two parameters and return a boolean result.
|
||||
|
||||
These are most commonly used with the `select` operator to filter particular nodes.
|
||||
|
||||
## Related Operators
|
||||
|
||||
- equals / not equals (`==`, `!=`) operators (here)[https://mikefarah.gitbook.io/yq/operators/equals]
|
||||
- comparison (`>=`, `<` etc) operators (here)[https://mikefarah.gitbook.io/yq/operators/compare]
|
||||
- select operator (here)[https://mikefarah.gitbook.io/yq/operators/select]
|
||||
|
||||
{% hint style="warning" %}
|
||||
Note that versions prior to 4.18 require the 'eval/e' command to be specified. 
|
||||
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
# 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)[https://mikefarah.gitbook.io/yq/operators/equals]
|
||||
- boolean operators (`and`, `or`, `any` etc) (here)[https://mikefarah.gitbook.io/yq/operators/boolean-operators]
|
||||
- select operator (here)[https://mikefarah.gitbook.io/yq/operators/select]
|
||||
|
||||
{% hint style="warning" %}
|
||||
Note that versions prior to 4.18 require the 'eval/e' command to be specified. 
|
||||
@@ -113,3 +128,37 @@ will output
|
||||
true
|
||||
```
|
||||
|
||||
## Compare strings
|
||||
Compares strings by their bytecode.
|
||||
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
a: zoo
|
||||
b: apple
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq '.a > .b' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
true
|
||||
```
|
||||
|
||||
## Compare date times
|
||||
You can compare date times. Assumes RFC3339 date time format, see [date-time operators](https://mikefarah.gitbook.io/yq/operators/date-time-operators) for more information.
|
||||
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
a: 2021-01-01T03:10:00Z
|
||||
b: 2020-01-01T03:10:00Z
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq '.a > .b' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
true
|
||||
```
|
||||
|
||||
|
||||
@@ -14,6 +14,13 @@ select(.a == .b)
|
||||
|
||||
The not equals `!=` operator returns `false` if the LHS is equal to the RHS.
|
||||
|
||||
## Related Operators
|
||||
|
||||
- comparison (`>=`, `<` etc) operators (here)[https://mikefarah.gitbook.io/yq/operators/compare]
|
||||
- boolean operators (`and`, `or`, `any` etc) (here)[https://mikefarah.gitbook.io/yq/operators/boolean-operators]
|
||||
- select operator (here)[https://mikefarah.gitbook.io/yq/operators/select]
|
||||
|
||||
|
||||
{% hint style="warning" %}
|
||||
Note that versions prior to 4.18 require the 'eval/e' command to be specified. 
|
||||
|
||||
|
||||
@@ -9,3 +9,9 @@ The `or` and `and` operators take two parameters and return a boolean result.
|
||||
`any_c(condition)` and `all_c(condition)` are like `any` and `all` but they take a condition expression that is used against each element to determine if it's `true`. Note: in `jq` you can simply pass a condition to `any` or `all` and it simply works - `yq` isn't that clever..yet
|
||||
|
||||
These are most commonly used with the `select` operator to filter particular nodes.
|
||||
|
||||
## Related Operators
|
||||
|
||||
- equals / not equals (`==`, `!=`) operators (here)[https://mikefarah.gitbook.io/yq/operators/equals]
|
||||
- comparison (`>=`, `<` etc) operators (here)[https://mikefarah.gitbook.io/yq/operators/compare]
|
||||
- select operator (here)[https://mikefarah.gitbook.io/yq/operators/select]
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
# 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)[https://mikefarah.gitbook.io/yq/operators/equals]
|
||||
- boolean operators (`and`, `or`, `any` etc) (here)[https://mikefarah.gitbook.io/yq/operators/boolean-operators]
|
||||
- select operator (here)[https://mikefarah.gitbook.io/yq/operators/select]
|
||||
@@ -13,3 +13,10 @@ select(.a == .b)
|
||||
```
|
||||
|
||||
The not equals `!=` operator returns `false` if the LHS is equal to the RHS.
|
||||
|
||||
## Related Operators
|
||||
|
||||
- comparison (`>=`, `<` etc) operators (here)[https://mikefarah.gitbook.io/yq/operators/compare]
|
||||
- boolean operators (`and`, `or`, `any` etc) (here)[https://mikefarah.gitbook.io/yq/operators/boolean-operators]
|
||||
- select operator (here)[https://mikefarah.gitbook.io/yq/operators/select]
|
||||
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
# Select
|
||||
|
||||
Select is used to filter arrays and maps by a boolean expression.
|
||||
|
||||
## Related Operators
|
||||
|
||||
- equals / not equals (`==`, `!=`) operators (here)[https://mikefarah.gitbook.io/yq/operators/equals]
|
||||
- comparison (`>=`, `<` etc) operators (here)[https://mikefarah.gitbook.io/yq/operators/compare]
|
||||
- boolean operators (`and`, `or`, `any` etc) (here)[https://mikefarah.gitbook.io/yq/operators/boolean-operators]
|
||||
|
||||
@@ -2,6 +2,12 @@
|
||||
|
||||
Select is used to filter arrays and maps by a boolean expression.
|
||||
|
||||
## Related Operators
|
||||
|
||||
- equals / not equals (`==`, `!=`) operators (here)[https://mikefarah.gitbook.io/yq/operators/equals]
|
||||
- comparison (`>=`, `<` etc) operators (here)[https://mikefarah.gitbook.io/yq/operators/compare]
|
||||
- boolean operators (`and`, `or`, `any` etc) (here)[https://mikefarah.gitbook.io/yq/operators/boolean-operators]
|
||||
|
||||
{% hint style="warning" %}
|
||||
Note that versions prior to 4.18 require the 'eval/e' command to be specified. 
|
||||
|
||||
|
||||
Reference in New Issue
Block a user