mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-19 18:35:19 +00:00
Simplified yq usage
This commit is contained in:
parent
e84a50db2e
commit
9896245f71
101
operators/add.md
101
operators/add.md
@ -4,8 +4,10 @@ Add behaves differently according to the type of the LHS:
|
|||||||
* arrays: concatenate
|
* arrays: concatenate
|
||||||
* number scalars: arithmetic addition
|
* number scalars: arithmetic addition
|
||||||
* string scalars: concatenate
|
* string scalars: concatenate
|
||||||
|
* maps: shallow merge (use the multiply operator (`*`) to deeply merge)
|
||||||
|
|
||||||
|
Use `+=` as a relative append assign for things like increment. Note that `.a += .x` is equivalent to running `.a = .a + .x`.
|
||||||
|
|
||||||
Use `+=` as append assign for things like increment. Note that `.a += .x` is equivalent to running `.a = .a + .x`.
|
|
||||||
|
|
||||||
## Concatenate and assign arrays
|
## Concatenate and assign arrays
|
||||||
Given a sample.yml file of:
|
Given a sample.yml file of:
|
||||||
@ -18,7 +20,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a.b += ["cow"]' sample.yml
|
yq '.a.b += ["cow"]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -42,7 +44,7 @@ b:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a + .b' sample.yml
|
yq '.a + .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -61,7 +63,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a + null' sample.yml
|
yq '.a + null' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -77,7 +79,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a + {"cat": "meow"}' sample.yml
|
yq '.a + {"cat": "meow"}' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -94,7 +96,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a + "hello"' sample.yml
|
yq '.a + "hello"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -115,7 +117,7 @@ b:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a = .a + .b' sample.yml
|
yq '.a = .a + .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -141,7 +143,7 @@ b:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a += .b' sample.yml
|
yq '.a += .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -169,7 +171,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a[].b += ["mouse"]' sample.yml
|
yq '.a[].b += ["mouse"]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -193,7 +195,7 @@ b: meow
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a = .a + .b' sample.yml
|
yq '.a = .a + .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -211,7 +213,7 @@ b: 4.9
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a = .a + .b' sample.yml
|
yq '.a = .a + .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -229,7 +231,7 @@ b: 4
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a = .a + .b' sample.yml
|
yq '.a = .a + .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -245,7 +247,7 @@ b: 5
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[] += 1' sample.yml
|
yq '.[] += 1' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -258,10 +260,81 @@ Adding to null simply returns the rhs
|
|||||||
|
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
yq eval --null-input 'null + "cat"'
|
yq --null-input 'null + "cat"'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
cat
|
cat
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Add maps to shallow merge
|
||||||
|
Adding objects together shallow merges them. Use `*` to deeply merge.
|
||||||
|
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
a:
|
||||||
|
thing:
|
||||||
|
name: Astuff
|
||||||
|
value: x
|
||||||
|
a1: cool
|
||||||
|
b:
|
||||||
|
thing:
|
||||||
|
name: Bstuff
|
||||||
|
legs: 3
|
||||||
|
b1: neat
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq '.a += .b' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
a:
|
||||||
|
thing:
|
||||||
|
name: Bstuff
|
||||||
|
legs: 3
|
||||||
|
a1: cool
|
||||||
|
b1: neat
|
||||||
|
b:
|
||||||
|
thing:
|
||||||
|
name: Bstuff
|
||||||
|
legs: 3
|
||||||
|
b1: neat
|
||||||
|
```
|
||||||
|
|
||||||
|
## Custom types: that are really strings
|
||||||
|
When custom tags are encountered, yq will try to decode the underlying type.
|
||||||
|
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
a: !horse cat
|
||||||
|
b: !goat _meow
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq '.a += .b' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
a: !horse cat_meow
|
||||||
|
b: !goat _meow
|
||||||
|
```
|
||||||
|
|
||||||
|
## Custom types: that are really numbers
|
||||||
|
When custom tags are encountered, yq will try to decode the underlying type.
|
||||||
|
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
a: !horse 1.2
|
||||||
|
b: !goat 2.3
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq '.a += .b' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
a: !horse 3.5
|
||||||
|
b: !goat 2.3
|
||||||
|
```
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ a: bridge
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a // "hello"' sample.yml
|
yq '.a // "hello"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -23,7 +23,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a // "hello"' sample.yml
|
yq '.a // "hello"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -37,7 +37,7 @@ a: ~
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a // "hello"' sample.yml
|
yq '.a // "hello"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -51,7 +51,7 @@ a: false
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a // "hello"' sample.yml
|
yq '.a // "hello"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -66,7 +66,7 @@ b: cat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a // .b' sample.yml
|
yq '.a // .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -25,7 +25,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[4] | explode(.)' sample.yml
|
yq '.[4] | explode(.)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -55,7 +55,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[4] | explode(.)' sample.yml
|
yq '.[4] | explode(.)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -87,7 +87,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[4] | explode(.)' sample.yml
|
yq '.[4] | explode(.)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -103,7 +103,7 @@ a: &billyBob cat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a | anchor' sample.yml
|
yq '.a | anchor' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -117,7 +117,7 @@ a: cat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a anchor = "foobar"' sample.yml
|
yq '.a anchor = "foobar"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -132,7 +132,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a anchor |= .b' sample.yml
|
yq '.a anchor |= .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -148,7 +148,7 @@ a: *billyBob
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a | alias' sample.yml
|
yq '.a | alias' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -163,7 +163,7 @@ a: cat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a alias = "meow"' sample.yml
|
yq '.a alias = "meow"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -179,7 +179,7 @@ a: cat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a alias = ""' sample.yml
|
yq '.a alias = ""' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -196,7 +196,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a alias |= .f' sample.yml
|
yq '.a alias |= .f' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -213,7 +213,7 @@ f:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'explode(.f)' sample.yml
|
yq 'explode(.f)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -229,7 +229,7 @@ a: mike
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'explode(.a)' sample.yml
|
yq 'explode(.a)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -245,7 +245,7 @@ f:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'explode(.f)' sample.yml
|
yq 'explode(.f)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -278,7 +278,7 @@ foobar:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'explode(.)' sample.yml
|
yq 'explode(.)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -317,7 +317,7 @@ thingTwo:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.thingOne |= explode(.) * {"value": false}' sample.yml
|
yq '.thingOne |= explode(.) * {"value": false}' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -10,7 +10,7 @@ This will do a similar thing to the plain form, however, the RHS expression is r
|
|||||||
## Create yaml file
|
## Create yaml file
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
yq eval --null-input '.a.b = "cat" | .x = "frog"'
|
yq --null-input '.a.b = "cat" | .x = "frog"'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -28,7 +28,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a |= .b' sample.yml
|
yq '.a |= .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -45,7 +45,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[] |= . * 2' sample.yml
|
yq '.[] |= . * 2' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -84,7 +84,7 @@ b: sibling
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a = .b' sample.yml
|
yq '.a = .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -101,7 +101,7 @@ c: fieldC
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '(.a, .c) = "potatoe"' sample.yml
|
yq '(.a, .c) = "potatoe"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -118,7 +118,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a.b = "frog"' sample.yml
|
yq '.a.b = "frog"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -136,7 +136,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a.b |= "frog"' sample.yml
|
yq '.a.b |= "frog"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -155,7 +155,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '(.a[] | select(. == "apple")) = "frog"' sample.yml
|
yq '(.a[] | select(. == "apple")) = "frog"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -173,7 +173,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '(.[] | select(. == "*andy")) = "bogs"' sample.yml
|
yq '(.[] | select(. == "*andy")) = "bogs"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -189,7 +189,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a.b |= "bogs"' sample.yml
|
yq '.a.b |= "bogs"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -205,7 +205,7 @@ a: &cool cat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a = "dog"' sample.yml
|
yq '.a = "dog"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -219,7 +219,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a.b.[0] |= "bogs"' sample.yml
|
yq '.a.b.[0] |= "bogs"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -13,7 +13,7 @@ These are most commonly used with the `select` operator to filter particular nod
|
|||||||
## `or` example
|
## `or` example
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
yq eval --null-input 'true or false'
|
yq --null-input 'true or false'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -23,7 +23,7 @@ true
|
|||||||
## `and` example
|
## `and` example
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
yq eval --null-input 'true and false'
|
yq --null-input 'true and false'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -42,7 +42,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '[.[] | select(.a == "cat" or .b == "dog")]' sample.yml
|
yq '[.[] | select(.a == "cat" or .b == "dog")]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -60,7 +60,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'any' sample.yml
|
yq 'any' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -74,7 +74,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'any' sample.yml
|
yq 'any' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -93,7 +93,7 @@ b:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[] |= any_c(. == "awesome")' sample.yml
|
yq '.[] |= any_c(. == "awesome")' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -109,7 +109,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'all' sample.yml
|
yq 'all' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -123,7 +123,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'all' sample.yml
|
yq 'all' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -142,7 +142,7 @@ b:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[] |= all_c(tag == "!!str")' sample.yml
|
yq '.[] |= all_c(tag == "!!str")' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -153,7 +153,7 @@ b: false
|
|||||||
## Not true is false
|
## Not true is false
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
yq eval --null-input 'true | not'
|
yq --null-input 'true | not'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -163,7 +163,7 @@ false
|
|||||||
## Not false is true
|
## Not false is true
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
yq eval --null-input 'false | not'
|
yq --null-input 'false | not'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -173,7 +173,7 @@ true
|
|||||||
## String values considered to be true
|
## String values considered to be true
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
yq eval --null-input '"cat" | not'
|
yq --null-input '"cat" | not'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -183,7 +183,7 @@ false
|
|||||||
## Empty string value considered to be true
|
## Empty string value considered to be true
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
yq eval --null-input '"" | not'
|
yq --null-input '"" | not'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -193,7 +193,7 @@ false
|
|||||||
## Numbers are considered to be true
|
## Numbers are considered to be true
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
yq eval --null-input '1 | not'
|
yq --null-input '1 | not'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -203,7 +203,7 @@ false
|
|||||||
## Zero is considered to be true
|
## Zero is considered to be true
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
yq eval --null-input '0 | not'
|
yq --null-input '0 | not'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -213,7 +213,7 @@ false
|
|||||||
## Null is considered to be false
|
## Null is considered to be false
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
yq eval --null-input '~ | not'
|
yq --null-input '~ | not'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -6,7 +6,7 @@ This creates an array using the expression between the square brackets.
|
|||||||
## Collect empty
|
## Collect empty
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
yq eval --null-input '[]'
|
yq --null-input '[]'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -16,7 +16,7 @@ will output
|
|||||||
## Collect single
|
## Collect single
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
yq eval --null-input '["cat"]'
|
yq --null-input '["cat"]'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -31,7 +31,7 @@ b: dog
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '[.a, .b]' sample.yml
|
yq '[.a, .b]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -17,7 +17,7 @@ a: cat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a lineComment="single"' sample.yml
|
yq '.a lineComment="single"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -32,7 +32,7 @@ b: dog
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.. lineComment |= .' sample.yml
|
yq '.. lineComment |= .' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -47,7 +47,7 @@ a: cat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '. headComment="single"' sample.yml
|
yq '. headComment="single"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -63,7 +63,7 @@ a: cat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '. footComment=.a' sample.yml
|
yq '. footComment=.a' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -80,7 +80,7 @@ b: dog # leave this
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a lineComment=""' sample.yml
|
yq '.a lineComment=""' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -99,7 +99,7 @@ b: # key comment
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '... comments=""' sample.yml
|
yq '... comments=""' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -114,7 +114,7 @@ a: cat # meow
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a | lineComment' sample.yml
|
yq '.a | lineComment' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -132,7 +132,7 @@ a: cat # meow
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '. | headComment' sample.yml
|
yq '. | headComment' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -151,7 +151,7 @@ a: cat # meow
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'headComment' sample.yml
|
yq 'headComment' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -171,7 +171,7 @@ a: cat # meow
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '. | footComment' sample.yml
|
yq '. | footComment' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -13,7 +13,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'contains(["baz", "bar"])' sample.yml
|
yq 'contains(["baz", "bar"])' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -32,7 +32,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'contains({"bar": [{"barp": 12}]})' sample.yml
|
yq 'contains({"bar": [{"barp": 12}]})' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -51,7 +51,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'contains({"foo": 12, "bar": [{"barp": 15}]})' sample.yml
|
yq 'contains({"foo": 12, "bar": [{"barp": 15}]})' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -65,7 +65,7 @@ foobar
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'contains("bar")' sample.yml
|
yq 'contains("bar")' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -79,7 +79,7 @@ meow
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'contains("meow")' sample.yml
|
yq 'contains("meow")' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -5,7 +5,7 @@ This is used to construct objects (or maps). This can be used against existing y
|
|||||||
## Collect empty object
|
## Collect empty object
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
yq eval --null-input '{}'
|
yq --null-input '{}'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -19,7 +19,7 @@ name: Mike
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '{"wrap": .}' sample.yml
|
yq '{"wrap": .}' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -37,7 +37,7 @@ pets:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '{.name: .pets.[]}' sample.yml
|
yq '{.name: .pets.[]}' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -60,7 +60,7 @@ pets:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '{.name: .pets.[]}' sample.yml
|
yq '{.name: .pets.[]}' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -73,7 +73,7 @@ Rosey: sheep
|
|||||||
## Creating yaml from scratch
|
## Creating yaml from scratch
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
yq eval --null-input '{"wrap": "frog"}'
|
yq --null-input '{"wrap": "frog"}'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -10,7 +10,7 @@ b: dog
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'del(.b)' sample.yml
|
yq 'del(.b)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -26,7 +26,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'del(.a.a1)' sample.yml
|
yq 'del(.a.a1)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -43,7 +43,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'del(.[1])' sample.yml
|
yq 'del(.[1])' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -59,7 +59,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'del(.[0].a)' sample.yml
|
yq 'del(.[0].a)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -74,7 +74,7 @@ b: dog
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'del(.c)' sample.yml
|
yq 'del(.c)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -91,7 +91,7 @@ c: bat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'del( .[] | select(. == "*at") )' sample.yml
|
yq 'del( .[] | select(. == "*at") )' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -109,7 +109,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'del(.. | select(has("name")).name)' sample.yml
|
yq 'del(.. | select(has("name")).name)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -11,7 +11,7 @@ a: frog
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a | documentIndex' sample.yml
|
yq '.a | documentIndex' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -29,7 +29,7 @@ a: frog
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a | di' sample.yml
|
yq '.a | di' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -47,7 +47,7 @@ a: frog
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'select(documentIndex == 1)' sample.yml
|
yq 'select(documentIndex == 1)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -63,7 +63,7 @@ a: frog
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'select(di == 1)' sample.yml
|
yq 'select(di == 1)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -79,7 +79,7 @@ a: frog
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a | ({"match": ., "doc": documentIndex})' sample.yml
|
yq '.a | ({"match": ., "doc": documentIndex})' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -30,7 +30,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.b = (.a | to_json)' sample.yml
|
yq '.b = (.a | to_json)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -52,7 +52,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.b = (.a | to_json(0))' sample.yml
|
yq '.b = (.a | to_json(0))' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -71,7 +71,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.b = (.a | @json)' sample.yml
|
yq '.b = (.a | @json)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -89,7 +89,7 @@ a: '{"cool":"thing"}'
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a | from_json | ... style=""' sample.yml
|
yq '.a | from_json | ... style=""' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -104,7 +104,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.b = (.a | @props)' sample.yml
|
yq '.b = (.a | @props)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -125,7 +125,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.b = (.a | to_yaml)' sample.yml
|
yq '.b = (.a | to_yaml)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -148,7 +148,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.b = (.a | to_yaml(8))' sample.yml
|
yq '.b = (.a | to_yaml(8))' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -167,7 +167,7 @@ a: 'foo: bar'
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.b = (.a | from_yaml)' sample.yml
|
yq '.b = (.a | from_yaml)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -186,7 +186,7 @@ a: |
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a |= (from_yaml | .foo = "cat" | to_yaml)' sample.yml
|
yq '.a |= (from_yaml | .foo = "cat" | to_yaml)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -202,7 +202,7 @@ a: 'foo: bar'
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a |= (from_yaml | .foo = "cat" | to_yaml)' sample.yml
|
yq '.a |= (from_yaml | .foo = "cat" | to_yaml)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -221,7 +221,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '@csv' sample.yml
|
yq '@csv' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -242,7 +242,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '@csv' sample.yml
|
yq '@csv' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -266,7 +266,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '@tsv' sample.yml
|
yq '@tsv' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -284,7 +284,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a | to_xml' sample.yml
|
yq '.a | to_xml' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -304,7 +304,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a | @xml' sample.yml
|
yq '.a | @xml' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -322,7 +322,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '{"cat": .a | to_xml(1)}' sample.yml
|
yq '{"cat": .a | to_xml(1)}' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -339,7 +339,7 @@ a: <foo>bar</foo>
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.b = (.a | from_xml)' sample.yml
|
yq '.b = (.a | from_xml)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -10,7 +10,7 @@ b: 2
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'to_entries' sample.yml
|
yq 'to_entries' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -28,7 +28,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'to_entries' sample.yml
|
yq 'to_entries' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -45,7 +45,7 @@ null
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'to_entries' sample.yml
|
yq 'to_entries' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -59,7 +59,7 @@ b: 2
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'to_entries | from_entries' sample.yml
|
yq 'to_entries | from_entries' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -77,7 +77,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'to_entries | from_entries' sample.yml
|
yq 'to_entries | from_entries' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -93,7 +93,7 @@ b: 2
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'with_entries(.key |= "KEY_" + .)' sample.yml
|
yq 'with_entries(.key |= "KEY_" + .)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -111,7 +111,7 @@ c:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'with_entries(select(.value | has("b")))' sample.yml
|
yq 'with_entries(select(.value | has("b")))' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -1,11 +1,26 @@
|
|||||||
# Env Variable Operators
|
# Env Variable Operators
|
||||||
|
|
||||||
This operator is used to handle environment variables usage in path expressions. While environment variables can, of course, be passed in via your CLI with string interpolation, this often comes with complex quote escaping and can be tricky to write and read. Note that there are two forms, `env` which will parse the environment variable as a yaml (be it a map, array, string, number of boolean) and `strenv` which will always parse the argument as a string.
|
These operators are used to handle environment variables usage in expressions and documents. While environment variables can, of course, be passed in via your CLI with string interpolation, this often comes with complex quote escaping and can be tricky to write and read.
|
||||||
|
|
||||||
|
There are three operators:
|
||||||
|
- `env` which takes a single environment variable name and parse the variable as a yaml node (be it a map, array, string, number of boolean)
|
||||||
|
- `strenv` which also takes a single environment variable name, and always parses the variable as a string.
|
||||||
|
- `envsubst` which you pipe strings into and it interpolates environment variables in strings using [envsubst](https://github.com/a8m/envsubst).
|
||||||
|
|
||||||
|
|
||||||
|
## Tip
|
||||||
|
To replace environment variables across all values in a document, `envsubst` can be used with the recursive descent operator
|
||||||
|
as follows:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
yq '(.. | select(tag == "!!str")) |= envsubst' file.yaml
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Read string environment variable
|
## Read string environment variable
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
myenv="cat meow" yq eval --null-input '.a = env(myenv)'
|
myenv="cat meow" yq --null-input '.a = env(myenv)'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -15,7 +30,7 @@ a: cat meow
|
|||||||
## Read boolean environment variable
|
## Read boolean environment variable
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
myenv="true" yq eval --null-input '.a = env(myenv)'
|
myenv="true" yq --null-input '.a = env(myenv)'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -25,7 +40,7 @@ a: true
|
|||||||
## Read numeric environment variable
|
## Read numeric environment variable
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
myenv="12" yq eval --null-input '.a = env(myenv)'
|
myenv="12" yq --null-input '.a = env(myenv)'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -35,7 +50,7 @@ a: 12
|
|||||||
## Read yaml environment variable
|
## Read yaml environment variable
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
myenv="{b: fish}" yq eval --null-input '.a = env(myenv)'
|
myenv="{b: fish}" yq --null-input '.a = env(myenv)'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -45,7 +60,7 @@ a: {b: fish}
|
|||||||
## Read boolean environment variable as a string
|
## Read boolean environment variable as a string
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
myenv="true" yq eval --null-input '.a = strenv(myenv)'
|
myenv="true" yq --null-input '.a = strenv(myenv)'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -55,7 +70,7 @@ a: "true"
|
|||||||
## Read numeric environment variable as a string
|
## Read numeric environment variable as a string
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
myenv="12" yq eval --null-input '.a = strenv(myenv)'
|
myenv="12" yq --null-input '.a = strenv(myenv)'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -70,10 +85,54 @@ dog: woof
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
myenv="cat" yq eval '.[env(myenv)]' sample.yml
|
myenv="cat" yq '.[env(myenv)]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
meow
|
meow
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Replace strings with envsubst
|
||||||
|
Running
|
||||||
|
```bash
|
||||||
|
myenv="cat" yq --null-input '"the ${myenv} meows" | envsubst'
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
the cat meows
|
||||||
|
```
|
||||||
|
|
||||||
|
## Replace strings with envsubst, missing variables
|
||||||
|
Running
|
||||||
|
```bash
|
||||||
|
myenv="cat" yq --null-input '"the ${myenvnonexisting} meows" | envsubst'
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
the meows
|
||||||
|
```
|
||||||
|
|
||||||
|
## Replace strings with envsubst, missing variables with defaults
|
||||||
|
Running
|
||||||
|
```bash
|
||||||
|
myenv="cat" yq --null-input '"the ${myenvnonexisting-dog} meows" | envsubst'
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
the dog meows
|
||||||
|
```
|
||||||
|
|
||||||
|
## Replace string environment variable in document
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
v: ${myenv}
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
myenv="cat meow" yq '.v |= envsubst' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
v: cat meow
|
||||||
|
```
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[] | (. == "*at")' sample.yml
|
yq '.[] | (. == "*at")' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -39,7 +39,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[] | (. != "*at")' sample.yml
|
yq '.[] | (. != "*at")' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -57,7 +57,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[] | (. == 4)' sample.yml
|
yq '.[] | (. == 4)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -75,7 +75,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[] | (. != 4)' sample.yml
|
yq '.[] | (. != 4)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -87,7 +87,7 @@ true
|
|||||||
## Match nulls
|
## Match nulls
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
yq eval --null-input 'null == ~'
|
yq --null-input 'null == ~'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -101,7 +101,7 @@ a: frog
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'select(.b != "thing")' sample.yml
|
yq 'select(.b != "thing")' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -115,7 +115,7 @@ a: frog
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'select(.b == .c)' sample.yml
|
yq 'select(.b == .c)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -17,7 +17,7 @@ a: cat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'filename' sample.yml
|
yq 'filename' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -31,7 +31,7 @@ a: cat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'fileIndex' sample.yml
|
yq 'fileIndex' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -65,7 +65,7 @@ a: cat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'fi' sample.yml
|
yq 'fi' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -12,7 +12,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'flatten' sample.yml
|
yq 'flatten' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -30,7 +30,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'flatten(1)' sample.yml
|
yq 'flatten(1)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -46,7 +46,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'flatten' sample.yml
|
yq 'flatten' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -61,7 +61,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'flatten' sample.yml
|
yq 'flatten' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -14,7 +14,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'group_by(.foo)' sample.yml
|
yq 'group_by(.foo)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -40,7 +40,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'group_by(.foo)' sample.yml
|
yq 'group_by(.foo)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -12,7 +12,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[] | has("a")' sample.yml
|
yq '.[] | has("a")' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -36,7 +36,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[] | select(.a.b | has("c"))' sample.yml
|
yq '.[] | select(.a.b | has("c"))' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -57,7 +57,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[] | has(1)' sample.yml
|
yq '.[] | has(1)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -10,7 +10,7 @@ cat: meow
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'keys' sample.yml
|
yq 'keys' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -26,7 +26,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'keys' sample.yml
|
yq 'keys' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -43,7 +43,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[1] | key' sample.yml
|
yq '.[1] | key' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -57,7 +57,7 @@ a: thing
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a | key' sample.yml
|
yq '.a | key' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -71,7 +71,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'key' sample.yml
|
yq 'key' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -86,7 +86,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '(.a.x | key) = "meow"' sample.yml
|
yq '(.a.x | key) = "meow"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -105,7 +105,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a.x | key | headComment' sample.yml
|
yq '.a.x | key | headComment' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -11,7 +11,7 @@ a: cat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a | length' sample.yml
|
yq '.a | length' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -25,7 +25,7 @@ a: null
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a | length' sample.yml
|
yq '.a | length' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -42,7 +42,7 @@ c: dog
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'length' sample.yml
|
yq 'length' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -61,7 +61,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'length' sample.yml
|
yq 'length' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -20,7 +20,7 @@ myFile: ../../examples/thing.yml
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'load(.myFile)' sample.yml
|
yq 'load(.myFile)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -38,7 +38,7 @@ something:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.something |= load("../../examples/" + .file)' sample.yml
|
yq '.something |= load("../../examples/" + .file)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -60,7 +60,7 @@ over:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '(.. | select(has("file"))) |= load("../../examples/" + .file)' sample.yml
|
yq '(.. | select(has("file"))) |= load("../../examples/" + .file)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -83,7 +83,7 @@ something:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.something |= strload("../../examples/" + .file)' sample.yml
|
yq '.something |= strload("../../examples/" + .file)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -11,7 +11,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'map(. + 1)' sample.yml
|
yq 'map(. + 1)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -29,7 +29,7 @@ c: 3
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'map_values(. + 1)' sample.yml
|
yq 'map_values(. + 1)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -23,13 +23,19 @@ yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' file1.yaml file2.y
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Multiply integers
|
## Multiply integers
|
||||||
Running
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
a: 3
|
||||||
|
b: 4
|
||||||
|
```
|
||||||
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval --null-input '3 * 4'
|
yq '.a *= .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
12
|
a: 12
|
||||||
|
b: 4
|
||||||
```
|
```
|
||||||
|
|
||||||
## Merge objects together, returning merged result only
|
## Merge objects together, returning merged result only
|
||||||
@ -45,7 +51,7 @@ b:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a * .b' sample.yml
|
yq '.a * .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -68,7 +74,7 @@ b:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '. * {"a":.b}' sample.yml
|
yq '. * {"a":.b}' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -92,7 +98,7 @@ b:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '. * {"a":.b}' sample.yml
|
yq '. * {"a":.b}' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -115,7 +121,7 @@ b:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '. * {"a":.b}' sample.yml
|
yq '. * {"a":.b}' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -141,7 +147,7 @@ b:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a *? .b' sample.yml
|
yq '.a *? .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -161,7 +167,7 @@ b:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a *n .b' sample.yml
|
yq '.a *n .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -188,7 +194,7 @@ b:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a *+ .b' sample.yml
|
yq '.a *+ .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -218,7 +224,7 @@ b:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a *?+ .b' sample.yml
|
yq '.a *?+ .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -245,7 +251,7 @@ b:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a *d .b' sample.yml
|
yq '.a *d .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -325,7 +331,7 @@ b: dog
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '. * {"a": {"c": .a}}' sample.yml
|
yq '. * {"a": {"c": .a}}' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -346,7 +352,7 @@ c:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.c * .b' sample.yml
|
yq '.c * .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -366,7 +372,7 @@ c:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.c * .a' sample.yml
|
yq '.c * .a' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -398,7 +404,7 @@ foobar:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.foobar * .foobarList' sample.yml
|
yq '.foobar * .foobarList' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -410,3 +416,44 @@ thing: foobar_thing
|
|||||||
b: foobarList_b
|
b: foobarList_b
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Custom types: that are really numbers
|
||||||
|
When custom tags are encountered, yq will try to decode the underlying type.
|
||||||
|
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
a: !horse 2
|
||||||
|
b: !goat 3
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq '.a = .a * .b' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
a: !horse 6
|
||||||
|
b: !goat 3
|
||||||
|
```
|
||||||
|
|
||||||
|
## Custom types: that are really maps
|
||||||
|
Custom tags will be maintained.
|
||||||
|
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
a: !horse
|
||||||
|
cat: meow
|
||||||
|
b: !goat
|
||||||
|
dog: woof
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq '.a = .a * .b' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
a: !horse
|
||||||
|
cat: meow
|
||||||
|
dog: woof
|
||||||
|
b: !goat
|
||||||
|
dog: woof
|
||||||
|
```
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a.nested | parent' sample.yml
|
yq '.a.nested | parent' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -29,7 +29,7 @@ b:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.. | select(. == "banana") | parent' sample.yml
|
yq '.. | select(. == "banana") | parent' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -44,7 +44,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'parent' sample.yml
|
yq 'parent' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -12,7 +12,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a.b | path' sample.yml
|
yq '.a.b | path' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -28,7 +28,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a.b | path | .[-1]' sample.yml
|
yq '.a.b | path | .[-1]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -44,7 +44,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a.[] | select(. == "dog") | path' sample.yml
|
yq '.a.[] | select(. == "dog") | path' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -61,7 +61,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a.[] | select(. == "dog") | path | .[-1]' sample.yml
|
yq '.a.[] | select(. == "dog") | path | .[-1]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -78,7 +78,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a[] | select(. == "*og") | [{"path":path, "value":.}]' sample.yml
|
yq '.a[] | select(. == "*og") | [{"path":path, "value":.}]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -10,7 +10,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a | .b' sample.yml
|
yq '.a | .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -26,7 +26,7 @@ c: same
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a = "cat" | .b = "dog"' sample.yml
|
yq '.a = "cat" | .b = "dog"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -8,7 +8,7 @@ This will, like the `jq` equivalent, recursively match all _value_ nodes. Use it
|
|||||||
For instance to set the `style` of all _value_ nodes in a yaml doc, excluding map keys:
|
For instance to set the `style` of all _value_ nodes in a yaml doc, excluding map keys:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
yq eval '.. style= "flow"' file.yaml
|
yq '.. style= "flow"' file.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
## match values and map keys form `...`
|
## match values and map keys form `...`
|
||||||
@ -17,7 +17,7 @@ The also includes map keys in the results set. This is particularly useful in YA
|
|||||||
For instance to set the `style` of all nodes in a yaml doc, including the map keys:
|
For instance to set the `style` of all nodes in a yaml doc, including the map keys:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
yq eval '... style= "flow"' file.yaml
|
yq '... style= "flow"' file.yaml
|
||||||
```
|
```
|
||||||
## Recurse map (values only)
|
## Recurse map (values only)
|
||||||
Given a sample.yml file of:
|
Given a sample.yml file of:
|
||||||
@ -26,7 +26,7 @@ a: frog
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '..' sample.yml
|
yq '..' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -47,7 +47,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '[.. | select(has("name"))]' sample.yml
|
yq '[.. | select(has("name"))]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -70,7 +70,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.. | select(. == "frog")' sample.yml
|
yq '.. | select(. == "frog")' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -87,7 +87,7 @@ a: frog
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '...' sample.yml
|
yq '...' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -105,7 +105,7 @@ b: *cat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '[..]' sample.yml
|
yq '[..]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -142,7 +142,7 @@ foobar:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.foobar | [..]' sample.yml
|
yq '.foobar | [..]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -31,7 +31,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[] as $item ireduce (0; . + $item)' sample.yml
|
yq '.[] as $item ireduce (0; . + $item)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -67,7 +67,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[] as $item ireduce ({}; .[$item | .name] = ($item | .has) )' sample.yml
|
yq '.[] as $item ireduce ({}; .[$item | .name] = ($item | .has) )' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -11,7 +11,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[] | select(. == "*at")' sample.yml
|
yq '.[] | select(. == "*at")' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -28,7 +28,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[] | select(. == "go*")' sample.yml
|
yq '.[] | select(. == "go*")' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -46,7 +46,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[] | select(. == "*go*")' sample.yml
|
yq '.[] | select(. == "*go*")' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -67,7 +67,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[] | select(test("[a-zA-Z]+_[0-9]$"))' sample.yml
|
yq '.[] | select(test("[a-zA-Z]+_[0-9]$"))' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -84,7 +84,7 @@ horse: dog
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[] | select(. == "cat" or test("og$"))' sample.yml
|
yq '.[] | select(. == "cat" or test("og$"))' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -101,7 +101,7 @@ game: poker
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'with_entries(select(.key | test("ame$")))' sample.yml
|
yq 'with_entries(select(.key | test("ame$")))' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -121,7 +121,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '(.a.[] | select(. == "cat" or . == "goat")) |= "rabbit"' sample.yml
|
yq '(.a.[] | select(. == "cat" or . == "goat")) |= "rabbit"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -5,11 +5,13 @@ The Sort Keys operator sorts maps by their keys (based on their string value). T
|
|||||||
Sort is particularly useful for diffing two different yaml documents:
|
Sort is particularly useful for diffing two different yaml documents:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
yq eval -i -P 'sort_keys(..)' file1.yml
|
yq -i -P 'sort_keys(..)' file1.yml
|
||||||
yq eval -i -P 'sort_keys(..)' file2.yml
|
yq -i -P 'sort_keys(..)' file2.yml
|
||||||
diff file1.yml file2.yml
|
diff file1.yml file2.yml
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Note that `yq` does not yet consider anchors when sorting by keys - this may result in invalid yaml documents if your are using merge anchors.
|
||||||
|
|
||||||
## Sort keys of map
|
## Sort keys of map
|
||||||
Given a sample.yml file of:
|
Given a sample.yml file of:
|
||||||
```yaml
|
```yaml
|
||||||
@ -19,7 +21,7 @@ b: bing
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'sort_keys(.)' sample.yml
|
yq 'sort_keys(.)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -49,7 +51,7 @@ aParent:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'sort_keys(..)' sample.yml
|
yq 'sort_keys(..)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -13,7 +13,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'sort_by(.a)' sample.yml
|
yq 'sort_by(.a)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -32,7 +32,7 @@ cool:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.cool |= sort_by(.a)' sample.yml
|
yq '.cool |= sort_by(.a)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -54,7 +54,7 @@ cool:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.cool |= sort_by(keys | .[0])' sample.yml
|
yq '.cool |= sort_by(keys | .[0])' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -80,7 +80,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'sort_by(.a)' sample.yml
|
yq 'sort_by(.a)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -103,7 +103,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'sort_by(.a)' sample.yml
|
yq 'sort_by(.a)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -125,7 +125,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'sort' sample.yml
|
yq 'sort' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -5,7 +5,7 @@ This operator splits all matches into separate documents
|
|||||||
## Split empty
|
## Split empty
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
yq eval --null-input 'splitDoc'
|
yq --null-input 'splitDoc'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -20,7 +20,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[] | splitDoc' sample.yml
|
yq '.[] | splitDoc' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -17,13 +17,13 @@ a: |
|
|||||||
Using `$( exp )` wont work, as it will trim the trailing new line.
|
Using `$( exp )` wont work, as it will trim the trailing new line.
|
||||||
|
|
||||||
```
|
```
|
||||||
m=$(echo "cat\n") yq e -n '.a = strenv(m)'
|
m=$(echo "cat\n") yq -n '.a = strenv(m)'
|
||||||
a: cat
|
a: cat
|
||||||
```
|
```
|
||||||
|
|
||||||
However, using printf works:
|
However, using printf works:
|
||||||
```
|
```
|
||||||
printf -v m "cat\n" ; m="$m" yq e -n '.a = strenv(m)'
|
printf -v m "cat\n" ; m="$m" yq -n '.a = strenv(m)'
|
||||||
a: |
|
a: |
|
||||||
cat
|
cat
|
||||||
```
|
```
|
||||||
@ -31,7 +31,7 @@ a: |
|
|||||||
As well as having multiline expressions:
|
As well as having multiline expressions:
|
||||||
```
|
```
|
||||||
m="cat
|
m="cat
|
||||||
" yq e -n '.a = strenv(m)'
|
" yq -n '.a = strenv(m)'
|
||||||
a: |
|
a: |
|
||||||
cat
|
cat
|
||||||
```
|
```
|
||||||
@ -40,7 +40,7 @@ Similarly, if you're trying to set the content from a file, and want a trailing
|
|||||||
|
|
||||||
```
|
```
|
||||||
IFS= read -rd '' output < <(cat my_file)
|
IFS= read -rd '' output < <(cat my_file)
|
||||||
output=$output ./yq e '.data.values = strenv(output)' first.yml
|
output=$output ./yq '.data.values = strenv(output)' first.yml
|
||||||
```
|
```
|
||||||
|
|
||||||
## Join strings
|
## Join strings
|
||||||
@ -54,7 +54,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'join("; ")' sample.yml
|
yq 'join("; ")' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -68,7 +68,7 @@ foo bar foo
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'match("foo")' sample.yml
|
yq 'match("foo")' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -85,7 +85,7 @@ foo bar FOO
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '[match("(?i)foo"; "g")]' sample.yml
|
yq '[match("(?i)foo"; "g")]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -106,7 +106,7 @@ abc abc
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '[match("(abc)+"; "g")]' sample.yml
|
yq '[match("(abc)+"; "g")]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -133,7 +133,7 @@ foo bar foo foo foo
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '[match("foo (?P<bar123>bar)? foo"; "g")]' sample.yml
|
yq '[match("foo (?P<bar123>bar)? foo"; "g")]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -162,7 +162,7 @@ xyzzy-14
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'capture("(?P<a>[a-z]+)-(?P<n>[0-9]+)")' sample.yml
|
yq 'capture("(?P<a>[a-z]+)-(?P<n>[0-9]+)")' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -177,7 +177,7 @@ cat cat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'match("cat")' sample.yml
|
yq 'match("cat")' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -194,7 +194,7 @@ cat cat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '[match("cat"; "g")]' sample.yml
|
yq '[match("cat"; "g")]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -218,7 +218,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[] | test("at")' sample.yml
|
yq '.[] | test("at")' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -236,7 +236,7 @@ a: dogs are great
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a |= sub("dogs", "cats")' sample.yml
|
yq '.a |= sub("dogs", "cats")' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -254,7 +254,7 @@ b: heat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[] |= sub("(a)", "${1}r")' sample.yml
|
yq '.[] |= sub("(a)", "${1}r")' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -269,7 +269,7 @@ cat; meow; 1; ; true
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'split("; ")' sample.yml
|
yq 'split("; ")' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -287,7 +287,7 @@ word
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'split("; ")' sample.yml
|
yq 'split("; ")' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -11,7 +11,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a.b = "new" | .a.b style="double"' sample.yml
|
yq '.a.b = "new" | .a.b style="double"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -29,7 +29,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'with(.a.b ; . = "new" | . style="double")' sample.yml
|
yq 'with(.a.b ; . = "new" | . style="double")' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -48,7 +48,7 @@ e: true
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.. style="tagged"' sample.yml
|
yq '.. style="tagged"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -69,7 +69,7 @@ e: true
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.. style="double"' sample.yml
|
yq '.. style="double"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -89,7 +89,7 @@ e: true
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '... style="double"' sample.yml
|
yq '... style="double"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -109,7 +109,7 @@ e: true
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.. style="single"' sample.yml
|
yq '.. style="single"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -129,7 +129,7 @@ e: true
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.. style="literal"' sample.yml
|
yq '.. style="literal"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -153,7 +153,7 @@ e: true
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.. style="folded"' sample.yml
|
yq '.. style="folded"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -177,7 +177,7 @@ e: true
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.. style="flow"' sample.yml
|
yq '.. style="flow"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -196,7 +196,7 @@ a: cat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '... style=""' sample.yml
|
yq '... style=""' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -214,7 +214,7 @@ b: double
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[] style |= .' sample.yml
|
yq '.[] style |= .' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -229,7 +229,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.. | style' sample.yml
|
yq '.. | style' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -5,7 +5,7 @@ You can use subtract to subtract numbers, as well as removing elements from an a
|
|||||||
## Array subtraction
|
## Array subtraction
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
yq eval --null-input '[1,2] - [2,3]'
|
yq --null-input '[1,2] - [2,3]'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -15,7 +15,7 @@ will output
|
|||||||
## Array subtraction with nested array
|
## Array subtraction with nested array
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
yq eval --null-input '[[1], 1, 2] - [[1], 3]'
|
yq --null-input '[[1], 1, 2] - [[1], 3]'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -34,7 +34,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '. - [{"c": "d", "a": "b"}]' sample.yml
|
yq '. - [{"c": "d", "a": "b"}]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -51,7 +51,7 @@ b: 4.5
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a = .a - .b' sample.yml
|
yq '.a = .a - .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -69,7 +69,7 @@ b: 4.5
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a = .a - .b' sample.yml
|
yq '.a = .a - .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -87,7 +87,7 @@ b: 4
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a = .a - .b' sample.yml
|
yq '.a = .a - .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -103,7 +103,7 @@ b: 5
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[] -= 1' sample.yml
|
yq '.[] -= 1' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -111,3 +111,21 @@ a: 2
|
|||||||
b: 4
|
b: 4
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Custom types: that are really numbers
|
||||||
|
When custom tags are encountered, yq will try to decode the underlying type.
|
||||||
|
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
a: !horse 2
|
||||||
|
b: !goat 1
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq '.a -= .b' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
a: !horse 1
|
||||||
|
b: !goat 1
|
||||||
|
```
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ f: []
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.. | tag' sample.yml
|
yq '.. | tag' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -32,7 +32,7 @@ a: str
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a tag = "!!mikefarah"' sample.yml
|
yq '.a tag = "!!mikefarah"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -49,7 +49,7 @@ e: true
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '(.. | select(tag == "!!int")) tag= "!!str"' sample.yml
|
yq '(.. | select(tag == "!!int")) tag= "!!str"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -10,7 +10,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a' sample.yml
|
yq '.a' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -27,7 +27,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[]' sample.yml
|
yq '.[]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -44,7 +44,7 @@ cat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[]' sample.yml
|
yq '.[]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -59,7 +59,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.["{}"]' sample.yml
|
yq '.["{}"]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -75,7 +75,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a["key.withdots"]["another.key"]' sample.yml
|
yq '.a["key.withdots"]["another.key"]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -91,7 +91,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.["red rabbit"]' sample.yml
|
yq '.["red rabbit"]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -109,7 +109,7 @@ banana: soft yum
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[.b]' sample.yml
|
yq '.[.b]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -125,7 +125,7 @@ c: banana
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a.b' sample.yml
|
yq '.a.b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -143,7 +143,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a?' sample.yml
|
yq '.a?' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -158,7 +158,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a."*a*"' sample.yml
|
yq '.a."*a*"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -175,7 +175,7 @@ b: *cat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.b' sample.yml
|
yq '.b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -191,7 +191,7 @@ b: *cat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.b[]' sample.yml
|
yq '.b[]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -207,7 +207,7 @@ b: *cat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.b.c' sample.yml
|
yq '.b.c' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -223,7 +223,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[0]' sample.yml
|
yq '.[0]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -237,7 +237,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[1][0]' sample.yml
|
yq '.[1][0]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -251,7 +251,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[2]' sample.yml
|
yq '.[2]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -265,7 +265,7 @@ a: b
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[0]' sample.yml
|
yq '.[0]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -296,7 +296,7 @@ foobar:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.foobar.a' sample.yml
|
yq '.foobar.a' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -327,7 +327,7 @@ foobar:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.foobar.c' sample.yml
|
yq '.foobar.c' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -358,7 +358,7 @@ foobar:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.foobar.thing' sample.yml
|
yq '.foobar.thing' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -389,7 +389,7 @@ foobar:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.foobar[]' sample.yml
|
yq '.foobar[]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -424,7 +424,7 @@ foobar:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.foobarList.thing' sample.yml
|
yq '.foobarList.thing' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -455,7 +455,7 @@ foobar:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.foobarList[]' sample.yml
|
yq '.foobarList[]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -475,7 +475,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a[0, 2]' sample.yml
|
yq '.a[0, 2]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -5,7 +5,7 @@ This operator is used to combine different results together.
|
|||||||
## Combine scalars
|
## Combine scalars
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
yq eval --null-input '1, true, "cat"'
|
yq --null-input '1, true, "cat"'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -23,7 +23,7 @@ c: fieldC
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a, .c' sample.yml
|
yq '.a, .c' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -12,7 +12,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'unique' sample.yml
|
yq 'unique' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -33,7 +33,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'unique' sample.yml
|
yq 'unique' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -53,7 +53,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'unique_by(tag)' sample.yml
|
yq 'unique_by(tag)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -72,7 +72,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'unique_by(.name)' sample.yml
|
yq 'unique_by(.name)' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -11,7 +11,7 @@ a: cat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a as $foo | $foo' sample.yml
|
yq '.a as $foo | $foo' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -26,7 +26,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[] as $foo | $foo' sample.yml
|
yq '.[] as $foo | $foo' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -50,7 +50,7 @@ Given a sample.yml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.realnames as $names | .posts[] | {"title":.title, "author": $names[.author]}' sample.yml
|
yq '.realnames as $names | .posts[] | {"title":.title, "author": $names[.author]}' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -68,7 +68,7 @@ b: b_value
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a as $x | .b as $y | .b = $x | .a = $y' sample.yml
|
yq '.a as $x | .b as $y | .b = $x | .a = $y' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -87,7 +87,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a.b ref $x | $x = "new" | $x style="double"' sample.yml
|
yq '.a.b ref $x | $x = "new" | $x style="double"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -11,7 +11,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'with(.a.deeply.nested; . = "newValue" | . style="single")' sample.yml
|
yq 'with(.a.deeply.nested; . = "newValue" | . style="single")' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -30,7 +30,7 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'with(.a.deeply; .nested = "newValue" | .other= "newThing")' sample.yml
|
yq 'with(.a.deeply; .nested = "newValue" | .other= "newThing")' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -51,7 +51,7 @@ myArray:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval 'with(.myArray[]; .b = .a + " yum")' sample.yml
|
yq 'with(.myArray[]; .b = .a + " yum")' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -13,7 +13,7 @@ Given a sample.json file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq e -P '.' sample.json
|
yq -P '.' sample.json
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -29,7 +29,7 @@ Given a sample.json file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq e -P '.' sample.json
|
yq -P '.' sample.json
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -48,7 +48,7 @@ cat: meow
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq e -o=json '.' sample.yml
|
yq -o=json '.' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```json
|
```json
|
||||||
@ -64,7 +64,7 @@ cat: meow # this is a comment, and it will be dropped.
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq e -o=json -I=0 '.' sample.yml
|
yq -o=json -I=0 '.' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```json
|
```json
|
||||||
@ -78,7 +78,7 @@ cat: meow # this is a comment, and it will be dropped.
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq e -o=json '.' sample.yml
|
yq -o=json '.' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```json
|
```json
|
||||||
@ -97,7 +97,7 @@ anotherCat: *ref
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq e -o=json '.' sample.yml
|
yq -o=json '.' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```json
|
```json
|
||||||
@ -116,7 +116,7 @@ things: [{stuff: cool}, {whatever: cat}]
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq e -o=json -I=0 '.things[]' sample.yml
|
yq -o=json -I=0 '.things[]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```json
|
```json
|
||||||
|
24
usage/xml.md
24
usage/xml.md
@ -20,7 +20,7 @@ Given a sample.xml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq e -p=xml '.' sample.xml
|
yq -p=xml '.' sample.xml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -44,7 +44,7 @@ Given a sample.xml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq e -p=xml ' (.. | select(tag == "!!str")) |= from_yaml' sample.xml
|
yq -p=xml ' (.. | select(tag == "!!str")) |= from_yaml' sample.xml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -65,7 +65,7 @@ Given a sample.xml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq e -p=xml '.' sample.xml
|
yq -p=xml '.' sample.xml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -86,7 +86,7 @@ Given a sample.xml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq e -p=xml '.' sample.xml
|
yq -p=xml '.' sample.xml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -105,7 +105,7 @@ Given a sample.xml file of:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq e -p=xml '.' sample.xml
|
yq -p=xml '.' sample.xml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -140,7 +140,7 @@ for x --></x>
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq e -p=xml '.' sample.xml
|
yq -p=xml '.' sample.xml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -168,7 +168,7 @@ cat: purrs
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq e -o=xml '.' sample.yml
|
yq -o=xml '.' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```xml
|
```xml
|
||||||
@ -185,7 +185,7 @@ pets:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq e -o=xml '.' sample.yml
|
yq -o=xml '.' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```xml
|
```xml
|
||||||
@ -207,7 +207,7 @@ cat:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq e -o=xml '.' sample.yml
|
yq -o=xml '.' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```xml
|
```xml
|
||||||
@ -228,7 +228,7 @@ cat:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq e -o=xml '.' sample.yml
|
yq -o=xml '.' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```xml
|
```xml
|
||||||
@ -252,7 +252,7 @@ cat: # inline_cat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq e -o=xml '.' sample.yml
|
yq -o=xml '.' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```xml
|
```xml
|
||||||
@ -288,7 +288,7 @@ for x --></x>
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq e -p=xml -o=xml '.' sample.xml
|
yq -p=xml -o=xml '.' sample.xml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```xml
|
```xml
|
||||||
|
Loading…
Reference in New Issue
Block a user