diff --git a/how-it-works.md b/how-it-works.md index d5cb5f96..9f36a2b5 100644 --- a/how-it-works.md +++ b/how-it-works.md @@ -19,7 +19,7 @@ with an expression: .a = .b ``` -Like math expression - operator precedence is important. +Like math expressions - operator precedence is important. The `=` operator takes two arguments, a `lhs` expression, which in this case is `.a` and `rhs` expression which is `.b`. @@ -47,7 +47,7 @@ b: dog ## Complex assignment, operator precedence rules -Just like math expression - `yq` expression have an order of precedence. The pipe `|` operator has a low order of precedence, so operators with higher precedence will get evalated first. +Just like math expressions - `yq` expressions have an order of precedence. The pipe `|` operator has a low order of precedence, so operators with higher precedence will get evaluated first. Most of the time, this is intuitively what you'd want, for instance `.a = "cat" | .b = "dog"` is effectively: `(.a = "cat") | (.b = "dog")`. @@ -66,7 +66,7 @@ Lets say you had: Lets say you wanted to update the `sally` entry to have fruit: 'mango'. The _incorrect_ way to do that is: `.[] | select(.name == "sally") | .fruit = "mango"`. -Becasue `|` has a low operator precedence, this will be evaluated (_incorrectly_) as : `(.[]) | (select(.name == "sally")) | (.fruit = "mango")`. What you'll see is only the updated segment returned: +Because `|` has a low operator precedence, this will be evaluated (_incorrectly_) as : `(.[]) | (select(.name == "sally")) | (.fruit = "mango")`. What you'll see is only the updated segment returned: ```yaml name: sally diff --git a/operators/assign-update.md b/operators/assign-update.md index ff6b0860..ef97571d 100644 --- a/operators/assign-update.md +++ b/operators/assign-update.md @@ -107,13 +107,13 @@ c: fieldC ``` then ```bash -yq '(.a, .c) = "potatoe"' sample.yml +yq '(.a, .c) = "potato"' sample.yml ``` will output ```yaml -a: potatoe +a: potato b: fieldB -c: potatoe +c: potato ``` ## Update string value @@ -151,7 +151,7 @@ a: ``` ## Update deeply selected results -Note that the LHS is wrapped in brackets! This is to ensure we dont first filter out the yaml and then update the snippet. +Note that the LHS is wrapped in brackets! This is to ensure we don't first filter out the yaml and then update the snippet. Given a sample.yml file of: ```yaml diff --git a/operators/comment-operators.md b/operators/comment-operators.md index 9e3b61ec..e53c3fc5 100644 --- a/operators/comment-operators.md +++ b/operators/comment-operators.md @@ -74,7 +74,6 @@ yq '. foot_comment=.a' sample.yml will output ```yaml a: cat - # cat ``` @@ -117,6 +116,7 @@ b: Given a sample.yml file of: ```yaml a: cat # meow +# have a great day ``` then ```bash diff --git a/operators/encode-decode.md b/operators/encode-decode.md index ba902955..5332649f 100644 --- a/operators/encode-decode.md +++ b/operators/encode-decode.md @@ -4,7 +4,7 @@ Encode operators will take the piped in object structure and encode it as a stri Note that you can optionally pass an indent value to the encode functions (see below). -These operators are useful to process yaml documents that have stringified embeded yaml/json/props in them. +These operators are useful to process yaml documents that have stringified embedded yaml/json/props in them. | Format | Decode (from string) | Encode (to string) | diff --git a/operators/equals.md b/operators/equals.md index e1686e98..4126bf9d 100644 --- a/operators/equals.md +++ b/operators/equals.md @@ -81,7 +81,7 @@ true false ``` -## Dont match number +## Don't match number Given a sample.yml file of: ```yaml - 3 @@ -109,7 +109,7 @@ will output true ``` -## Non exisitant key doesn't equal a value +## Non existent key doesn't equal a value Given a sample.yml file of: ```yaml a: frog diff --git a/operators/multiply-merge.md b/operators/multiply-merge.md index f2a3fb52..9f04daed 100644 --- a/operators/multiply-merge.md +++ b/operators/multiply-merge.md @@ -29,6 +29,12 @@ Note the use of `eval-all` to ensure all documents are loaded into memory. yq eval-all '. as $item ireduce ({}; . * $item )' *.yml ``` +# Merging complex arrays together by a key field +By default - `yq` merge is naive. It merges maps when they match the key name, and arrays are merged either by appending them together, or merging the entries by their position in the array. + +For more complex array merging (e.g. merging items that match on a certain key) please see the example [here](https://mikefarah.gitbook.io/yq/operators/multiply-merge#merge-arrays-of-objects-together-matching-on-a-key) + + {% hint style="warning" %} Note that versions prior to 4.18 require the 'eval/e' command to be specified. diff --git a/operators/reduce.md b/operators/reduce.md index 37b21645..e06a2a23 100644 --- a/operators/reduce.md +++ b/operators/reduce.md @@ -19,7 +19,7 @@ On the RHS there is ``, the starting value of the accumulator and ` ## yq vs jq syntax Reduce syntax in `yq` is a little different from `jq` - as `yq` (currently) isn't as sophisticated as `jq` and its only supports infix notation (e.g. a + b, where the operator is in the middle of the two parameters) - where as `jq` uses a mix of infix notation with _prefix_ notation (e.g. `reduce a b` is like writing `+ a b`). -To that end, the reduce operator is called `ireduce` for backwards compatability if a `jq` like prefix version of `reduce` is ever added. +To that end, the reduce operator is called `ireduce` for backwards compatibility if a `jq` like prefix version of `reduce` is ever added. {% hint style="warning" %} Note that versions prior to 4.18 require the 'eval/e' command to be specified. diff --git a/operators/string-operators.md b/operators/string-operators.md index 14dfc50c..9f0f3227 100644 --- a/operators/string-operators.md +++ b/operators/string-operators.md @@ -266,7 +266,7 @@ will output ``` ## Test using regex -Like jq'q equivalent, this works like match but only returns true/false instead of full match details +Like jq's equivalent, this works like match but only returns true/false instead of full match details Given a sample.yml file of: ```yaml diff --git a/operators/unique.md b/operators/unique.md index 9ea330f6..c7bd23ba 100644 --- a/operators/unique.md +++ b/operators/unique.md @@ -1,6 +1,7 @@ # Unique -This is used to filter out duplicated items in an array. +This is used to filter out duplicated items in an array. Note that the original order of the array is maintained. + {% hint style="warning" %} Note that versions prior to 4.18 require the 'eval/e' command to be specified. diff --git a/operators/variable-operators.md b/operators/variable-operators.md index b06458f5..e7efcd05 100644 --- a/operators/variable-operators.md +++ b/operators/variable-operators.md @@ -46,7 +46,7 @@ Example taken from [jq](https://stedolan.github.io/jq/manual/#Variable/SymbolicB Given a sample.yml file of: ```yaml "posts": - - "title": Frist psot + - "title": First post "author": anon - "title": A well-written article "author": person1 @@ -60,7 +60,7 @@ yq '.realnames as $names | .posts[] | {"title":.title, "author": $names[.author] ``` will output ```yaml -title: Frist psot +title: First post author: Anonymous Coward title: A well-written article author: Person McPherson