mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-13 20:15:57 +00:00
v4.24.1
This commit is contained in:
parent
3cca5f7aff
commit
58f27a1f20
@ -21,6 +21,7 @@
|
|||||||
* [Collect into Array](operators/collect-into-array.md)
|
* [Collect into Array](operators/collect-into-array.md)
|
||||||
* [Column](operators/column.md)
|
* [Column](operators/column.md)
|
||||||
* [Comment Operators](operators/comment-operators.md)
|
* [Comment Operators](operators/comment-operators.md)
|
||||||
|
* [Compare Operators](operators/compare.md)
|
||||||
* [Contains](operators/contains.md)
|
* [Contains](operators/contains.md)
|
||||||
* [Create, Collect into Object](operators/create-collect-into-object.md)
|
* [Create, Collect into Object](operators/create-collect-into-object.md)
|
||||||
* [Date Time](operators/datetime.md)
|
* [Date Time](operators/datetime.md)
|
||||||
|
@ -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.
|
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" %}
|
{% hint style="warning" %}
|
||||||
Note that versions prior to 4.18 require the 'eval/e' command to be specified. 
|
Note that versions prior to 4.18 require the 'eval/e' command to be specified. 
|
||||||
|
|
||||||
|
106
operators/compare.md
Normal file
106
operators/compare.md
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
# 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. 
|
||||||
|
|
||||||
|
`yq e <exp> <file>`
|
||||||
|
{% endhint %}
|
||||||
|
|
||||||
|
## Compare numbers (>)
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
a: 5
|
||||||
|
b: 4
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq '.a > .b' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
true
|
||||||
|
```
|
||||||
|
|
||||||
|
## Compare equal numbers (>=)
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
a: 5
|
||||||
|
b: 5
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq '.a >= .b' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
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
|
||||||
|
```
|
||||||
|
|
||||||
|
## Both sides are null: > is false
|
||||||
|
Running
|
||||||
|
```bash
|
||||||
|
yq --null-input '.a > .b'
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
false
|
||||||
|
```
|
||||||
|
|
||||||
|
## Both sides are null: >= is true
|
||||||
|
Running
|
||||||
|
```bash
|
||||||
|
yq --null-input '.a >= .b'
|
||||||
|
```
|
||||||
|
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.
|
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" %}
|
{% hint style="warning" %}
|
||||||
Note that versions prior to 4.18 require the 'eval/e' command to be specified. 
|
Note that versions prior to 4.18 require the 'eval/e' command to be specified. 
|
||||||
|
|
||||||
|
@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
Select is used to filter arrays and maps by a boolean expression.
|
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" %}
|
{% hint style="warning" %}
|
||||||
Note that versions prior to 4.18 require the 'eval/e' command to be specified. 
|
Note that versions prior to 4.18 require the 'eval/e' command to be specified. 
|
||||||
|
|
||||||
|
25
usage/xml.md
25
usage/xml.md
@ -120,6 +120,31 @@ cat:
|
|||||||
+legs: "4"
|
+legs: "4"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Parse xml: custom dtd
|
||||||
|
DTD entities are ignored.
|
||||||
|
|
||||||
|
Given a sample.xml file of:
|
||||||
|
```xml
|
||||||
|
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!DOCTYPE root [
|
||||||
|
<!ENTITY writer "Blah.">
|
||||||
|
<!ENTITY copyright "Blah">
|
||||||
|
]>
|
||||||
|
<root>
|
||||||
|
<item>&writer;©right;</item>
|
||||||
|
</root>
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq -p=xml '.' sample.xml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
root:
|
||||||
|
item: '&writer;©right;'
|
||||||
|
```
|
||||||
|
|
||||||
## Parse xml: with comments
|
## Parse xml: with comments
|
||||||
A best attempt is made to preserve comments.
|
A best attempt is made to preserve comments.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user