Fixing typos

This commit is contained in:
Mike Farah 2022-05-25 11:01:35 +10:00
parent 27a14ec188
commit deb7aeb966
10 changed files with 23 additions and 16 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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) |

View File

@ -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

View File

@ -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. 

View File

@ -19,7 +19,7 @@ On the RHS there is `<init>`, the starting value of the accumulator and `<block>
## 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.&#x20;

View File

@ -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

View File

@ -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.&#x20;

View File

@ -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