From 58f27a1f20deec442c3442cf9eae8e3b6e99422d Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Mon, 28 Mar 2022 14:24:57 +1100 Subject: [PATCH] v4.24.1 --- SUMMARY.md | 1 + operators/boolean-operators.md | 6 ++ operators/compare.md | 106 +++++++++++++++++++++++++++++++++ operators/equals.md | 7 +++ operators/select.md | 6 ++ usage/xml.md | 25 ++++++++ 6 files changed, 151 insertions(+) create mode 100644 operators/compare.md diff --git a/SUMMARY.md b/SUMMARY.md index eeeadd6b..4f472b15 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -21,6 +21,7 @@ * [Collect into Array](operators/collect-into-array.md) * [Column](operators/column.md) * [Comment Operators](operators/comment-operators.md) + * [Compare Operators](operators/compare.md) * [Contains](operators/contains.md) * [Create, Collect into Object](operators/create-collect-into-object.md) * [Date Time](operators/datetime.md) diff --git a/operators/boolean-operators.md b/operators/boolean-operators.md index 70c19bd2..fb6ae394 100644 --- a/operators/boolean-operators.md +++ b/operators/boolean-operators.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. +## 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. diff --git a/operators/compare.md b/operators/compare.md new file mode 100644 index 00000000..577e6692 --- /dev/null +++ b/operators/compare.md @@ -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 ` +{% 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 +``` + diff --git a/operators/equals.md b/operators/equals.md index d108c9f0..21e0f496 100644 --- a/operators/equals.md +++ b/operators/equals.md @@ -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. diff --git a/operators/select.md b/operators/select.md index 43a35f12..7912fb11 100644 --- a/operators/select.md +++ b/operators/select.md @@ -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. diff --git a/usage/xml.md b/usage/xml.md index 17ca941f..fb200381 100644 --- a/usage/xml.md +++ b/usage/xml.md @@ -120,6 +120,31 @@ cat: +legs: "4" ``` +## Parse xml: custom dtd +DTD entities are ignored. + +Given a sample.xml file of: +```xml + + + + +]> + + &writer;©right; + +``` +then +```bash +yq -p=xml '.' sample.xml +``` +will output +```yaml +root: + item: '&writer;©right;' +``` + ## Parse xml: with comments A best attempt is made to preserve comments.