Updating docs

This commit is contained in:
Mike Farah 2022-01-27 17:21:10 +11:00
parent 6f27cb93d1
commit a6fc7aa881
57 changed files with 389 additions and 370 deletions

View File

@ -26,7 +26,7 @@ country: Australia
And we run a command:
```bash
yq eval 'predictWeatherOf(.country)'
yq 'predictWeatherOf(.country)'
```
it could output

View File

@ -11,32 +11,35 @@ yq is written in go - so you can download a dependency free binary for your plat
Read a value:
```bash
yq e '.a.b[0].c' file.yaml
yq '.a.b[0].c' file.yaml
```
Pipe from STDIN:
```bash
cat file.yaml | yq e '.a.b[0].c' -
cat file.yaml | yq '.a.b[0].c'
```
Update a yaml file, inplace
```bash
yq e -i '.a.b[0].c = "cool"' file.yaml
yq -i '.a.b[0].c = "cool"' file.yaml
```
Update using environment variables
```bash
NAME=mike yq e -i '.a.b[0].c = strenv(NAME)' file.yaml
NAME=mike yq -i '.a.b[0].c = strenv(NAME)' file.yaml
```
Merge multiple files
```
```bash
# note the use of `ea` to evaluate all the files at once
# instead of in sequence
yq ea '. as $item ireduce ({}; . * $item )' path/to/*.yml
```
Multiple updates to a yaml file
```bash
yq e -i '
yq -i '
.a.b[0].c = "cool" |
.x.y.z = "foobar" |
.person.name = strenv(NAME)
@ -82,16 +85,16 @@ snap install yq
`yq` installs with [_strict confinement_](https://docs.snapcraft.io/snap-confinement/6233) in snap, this means it doesn't have direct access to root files. To read root files you can:
```
sudo cat /etc/myfile | yq e '.a.path' -
sudo cat /etc/myfile | yq '.a.path'
```
And to write to a root file you can either use [sponge](https://linux.die.net/man/1/sponge):
```
sudo cat /etc/myfile | yq e '.a.path = "value"' - | sudo sponge /etc/myfile
sudo cat /etc/myfile | yq '.a.path = "value"' | sudo sponge /etc/myfile
```
or write to a temporary file:
```
sudo cat /etc/myfile | yq e '.a.path = "value"' | sudo tee /etc/myfile.tmp
sudo cat /etc/myfile | yq '.a.path = "value"' | sudo tee /etc/myfile.tmp
sudo mv /etc/myfile.tmp /etc/myfile
rm /etc/myfile.tmp
```
@ -101,14 +104,14 @@ rm /etc/myfile.tmp
#### Oneshot use:
```bash
docker run --rm -v "${PWD}":/workdir mikefarah/yq <command> [flags] [expression ]FILE...
docker run --rm -v "${PWD}":/workdir mikefarah/yq [command] [flags] [expression ]FILE...
```
Note that you can run `yq` in docker without network access and other privileges if you desire,
namely `--security-opt=no-new-privileges --cap-drop all --network none`.
```bash
podman run --rm -v "${PWD}":/workdir mikefarah/yq <command> [flags] [expression ]FILE...
podman run --rm -v "${PWD}":/workdir mikefarah/yq [command] [flags] [expression ]FILE...
```
#### Pipe in via STDIN:
@ -116,11 +119,11 @@ podman run --rm -v "${PWD}":/workdir mikefarah/yq <command> [flags] [expression
You'll need to pass the `-i\--interactive` flag to docker:
```bash
cat myfile.yml | docker run -i --rm mikefarah/yq e . -
cat myfile.yml | docker run -i --rm mikefarah/yq '.this.thing'
```
```bash
cat myfile.yml | podman run -i --rm mikefarah/yq e . -
cat myfile.yml | podman run -i --rm mikefarah/yq '.this.thing'
```
#### Run commands interactively:
@ -176,7 +179,7 @@ USER yq
- name: Set foobar to cool
uses: mikefarah/yq@master
with:
cmd: yq eval -i '.foo.bar = "cool"' 'config.yml'
cmd: yq -i '.foo.bar = "cool"' 'config.yml'
```
See https://mikefarah.gitbook.io/yq/usage/github-action for more.
@ -270,9 +273,17 @@ Usage:
yq [flags]
yq [command]
Examples:
# yq defaults to 'eval' command if no command is specified. See "yq eval --help" for more examples.
cat myfile.yml | yq '.stuff' # outputs the data at the "stuff" node from "myfile.yml"
yq -i '.stuff = "foo"' myfile.yml # update myfile.yml inplace
Available Commands:
completion Generate the autocompletion script for the specified shell
eval Apply the expression to each document in each yaml file in sequence
eval (default) Apply the expression to each document in each yaml file in sequence
eval-all Loads _all_ yaml documents of _all_ yaml files and runs expression once
help Help about any command
shell-completion Generate completion script

View File

@ -5,8 +5,8 @@ setUp() {
}
testBasicEvalRoundTrip() {
./yq e -n ".a = 123" > test.yml
X=$(./yq e '.a' test.yml)
./yq -n ".a = 123" > test.yml
X=$(./yq '.a' test.yml)
assertEquals 123 "$X"
}

View File

@ -16,8 +16,11 @@ func New() *cobra.Command {
See https://mikefarah.gitbook.io/yq/ for detailed documentation and examples.`,
Example: `
# yq defaults to 'eval' command if no command is specified. See "yq eval --help" for more examples.
cat myfile.yml | yq '.stuff' # outputs the data at the "stuff" node from "myfile.yml"
# read the "stuff" node from "myfile.yml"
cat myfile.yml | yq '.stuff'
# update myfile.yml in place
yq -i '.stuff = "foo"' myfile.yml # update myfile.yml inplace
`,

View File

@ -20,7 +20,7 @@ a:
```
then
```bash
yq eval '.a.b += ["cow"]' sample.yml
yq '.a.b += ["cow"]' sample.yml
```
will output
```yaml
@ -44,7 +44,7 @@ b:
```
then
```bash
yq eval '.a + .b' sample.yml
yq '.a + .b' sample.yml
```
will output
```yaml
@ -63,7 +63,7 @@ a:
```
then
```bash
yq eval '.a + null' sample.yml
yq '.a + null' sample.yml
```
will output
```yaml
@ -79,7 +79,7 @@ a:
```
then
```bash
yq eval '.a + {"cat": "meow"}' sample.yml
yq '.a + {"cat": "meow"}' sample.yml
```
will output
```yaml
@ -96,7 +96,7 @@ a:
```
then
```bash
yq eval '.a + "hello"' sample.yml
yq '.a + "hello"' sample.yml
```
will output
```yaml
@ -117,7 +117,7 @@ b:
```
then
```bash
yq eval '.a = .a + .b' sample.yml
yq '.a = .a + .b' sample.yml
```
will output
```yaml
@ -143,7 +143,7 @@ b:
```
then
```bash
yq eval '.a += .b' sample.yml
yq '.a += .b' sample.yml
```
will output
```yaml
@ -171,7 +171,7 @@ a:
```
then
```bash
yq eval '.a[].b += ["mouse"]' sample.yml
yq '.a[].b += ["mouse"]' sample.yml
```
will output
```yaml
@ -195,7 +195,7 @@ b: meow
```
then
```bash
yq eval '.a = .a + .b' sample.yml
yq '.a = .a + .b' sample.yml
```
will output
```yaml
@ -213,7 +213,7 @@ b: 4.9
```
then
```bash
yq eval '.a = .a + .b' sample.yml
yq '.a = .a + .b' sample.yml
```
will output
```yaml
@ -231,7 +231,7 @@ b: 4
```
then
```bash
yq eval '.a = .a + .b' sample.yml
yq '.a = .a + .b' sample.yml
```
will output
```yaml
@ -247,7 +247,7 @@ b: 5
```
then
```bash
yq eval '.[] += 1' sample.yml
yq '.[] += 1' sample.yml
```
will output
```yaml
@ -260,7 +260,7 @@ Adding to null simply returns the rhs
Running
```bash
yq eval --null-input 'null + "cat"'
yq --null-input 'null + "cat"'
```
will output
```yaml
@ -285,7 +285,7 @@ b:
```
then
```bash
yq eval '.a += .b' sample.yml
yq '.a += .b' sample.yml
```
will output
```yaml
@ -312,7 +312,7 @@ b: !goat _meow
```
then
```bash
yq eval '.a += .b' sample.yml
yq '.a += .b' sample.yml
```
will output
```yaml
@ -330,7 +330,7 @@ b: !goat 2.3
```
then
```bash
yq eval '.a += .b' sample.yml
yq '.a += .b' sample.yml
```
will output
```yaml

View File

@ -9,7 +9,7 @@ a: bridge
```
then
```bash
yq eval '.a // "hello"' sample.yml
yq '.a // "hello"' sample.yml
```
will output
```yaml
@ -23,7 +23,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.a // "hello"' sample.yml
yq '.a // "hello"' sample.yml
```
will output
```yaml
@ -37,7 +37,7 @@ a: ~
```
then
```bash
yq eval '.a // "hello"' sample.yml
yq '.a // "hello"' sample.yml
```
will output
```yaml
@ -51,7 +51,7 @@ a: false
```
then
```bash
yq eval '.a // "hello"' sample.yml
yq '.a // "hello"' sample.yml
```
will output
```yaml
@ -66,7 +66,7 @@ b: cat
```
then
```bash
yq eval '.a // .b' sample.yml
yq '.a // .b' sample.yml
```
will output
```yaml

View File

@ -25,7 +25,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[4] | explode(.)' sample.yml
yq '.[4] | explode(.)' sample.yml
```
will output
```yaml
@ -55,7 +55,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[4] | explode(.)' sample.yml
yq '.[4] | explode(.)' sample.yml
```
will output
```yaml
@ -87,7 +87,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[4] | explode(.)' sample.yml
yq '.[4] | explode(.)' sample.yml
```
will output
```yaml
@ -103,7 +103,7 @@ a: &billyBob cat
```
then
```bash
yq eval '.a | anchor' sample.yml
yq '.a | anchor' sample.yml
```
will output
```yaml
@ -117,7 +117,7 @@ a: cat
```
then
```bash
yq eval '.a anchor = "foobar"' sample.yml
yq '.a anchor = "foobar"' sample.yml
```
will output
```yaml
@ -132,7 +132,7 @@ a:
```
then
```bash
yq eval '.a anchor |= .b' sample.yml
yq '.a anchor |= .b' sample.yml
```
will output
```yaml
@ -148,7 +148,7 @@ a: *billyBob
```
then
```bash
yq eval '.a | alias' sample.yml
yq '.a | alias' sample.yml
```
will output
```yaml
@ -163,7 +163,7 @@ a: cat
```
then
```bash
yq eval '.a alias = "meow"' sample.yml
yq '.a alias = "meow"' sample.yml
```
will output
```yaml
@ -179,7 +179,7 @@ a: cat
```
then
```bash
yq eval '.a alias = ""' sample.yml
yq '.a alias = ""' sample.yml
```
will output
```yaml
@ -196,7 +196,7 @@ a:
```
then
```bash
yq eval '.a alias |= .f' sample.yml
yq '.a alias |= .f' sample.yml
```
will output
```yaml
@ -213,7 +213,7 @@ f:
```
then
```bash
yq eval 'explode(.f)' sample.yml
yq 'explode(.f)' sample.yml
```
will output
```yaml
@ -229,7 +229,7 @@ a: mike
```
then
```bash
yq eval 'explode(.a)' sample.yml
yq 'explode(.a)' sample.yml
```
will output
```yaml
@ -245,7 +245,7 @@ f:
```
then
```bash
yq eval 'explode(.f)' sample.yml
yq 'explode(.f)' sample.yml
```
will output
```yaml
@ -278,7 +278,7 @@ foobar:
```
then
```bash
yq eval 'explode(.)' sample.yml
yq 'explode(.)' sample.yml
```
will output
```yaml
@ -317,7 +317,7 @@ thingTwo:
```
then
```bash
yq eval '.thingOne |= explode(.) * {"value": false}' sample.yml
yq '.thingOne |= explode(.) * {"value": false}' sample.yml
```
will output
```yaml

View File

@ -10,7 +10,7 @@ This will do a similar thing to the plain form, however, the RHS expression is r
## Create yaml file
Running
```bash
yq eval --null-input '.a.b = "cat" | .x = "frog"'
yq --null-input '.a.b = "cat" | .x = "frog"'
```
will output
```yaml
@ -28,7 +28,7 @@ a:
```
then
```bash
yq eval '.a |= .b' sample.yml
yq '.a |= .b' sample.yml
```
will output
```yaml
@ -45,7 +45,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[] |= . * 2' sample.yml
yq '.[] |= . * 2' sample.yml
```
will output
```yaml
@ -84,7 +84,7 @@ b: sibling
```
then
```bash
yq eval '.a = .b' sample.yml
yq '.a = .b' sample.yml
```
will output
```yaml
@ -101,7 +101,7 @@ c: fieldC
```
then
```bash
yq eval '(.a, .c) = "potatoe"' sample.yml
yq '(.a, .c) = "potatoe"' sample.yml
```
will output
```yaml
@ -118,7 +118,7 @@ a:
```
then
```bash
yq eval '.a.b = "frog"' sample.yml
yq '.a.b = "frog"' sample.yml
```
will output
```yaml
@ -136,7 +136,7 @@ a:
```
then
```bash
yq eval '.a.b |= "frog"' sample.yml
yq '.a.b |= "frog"' sample.yml
```
will output
```yaml
@ -155,7 +155,7 @@ a:
```
then
```bash
yq eval '(.a[] | select(. == "apple")) = "frog"' sample.yml
yq '(.a[] | select(. == "apple")) = "frog"' sample.yml
```
will output
```yaml
@ -173,7 +173,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '(.[] | select(. == "*andy")) = "bogs"' sample.yml
yq '(.[] | select(. == "*andy")) = "bogs"' sample.yml
```
will output
```yaml
@ -189,7 +189,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.a.b |= "bogs"' sample.yml
yq '.a.b |= "bogs"' sample.yml
```
will output
```yaml
@ -205,7 +205,7 @@ a: &cool cat
```
then
```bash
yq eval '.a = "dog"' sample.yml
yq '.a = "dog"' sample.yml
```
will output
```yaml
@ -219,7 +219,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.a.b.[0] |= "bogs"' sample.yml
yq '.a.b.[0] |= "bogs"' sample.yml
```
will output
```yaml

View File

@ -13,7 +13,7 @@ These are most commonly used with the `select` operator to filter particular nod
## `or` example
Running
```bash
yq eval --null-input 'true or false'
yq --null-input 'true or false'
```
will output
```yaml
@ -23,7 +23,7 @@ true
## `and` example
Running
```bash
yq eval --null-input 'true and false'
yq --null-input 'true and false'
```
will output
```yaml
@ -42,7 +42,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '[.[] | select(.a == "cat" or .b == "dog")]' sample.yml
yq '[.[] | select(.a == "cat" or .b == "dog")]' sample.yml
```
will output
```yaml
@ -60,7 +60,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'any' sample.yml
yq 'any' sample.yml
```
will output
```yaml
@ -74,7 +74,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'any' sample.yml
yq 'any' sample.yml
```
will output
```yaml
@ -93,7 +93,7 @@ b:
```
then
```bash
yq eval '.[] |= any_c(. == "awesome")' sample.yml
yq '.[] |= any_c(. == "awesome")' sample.yml
```
will output
```yaml
@ -109,7 +109,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'all' sample.yml
yq 'all' sample.yml
```
will output
```yaml
@ -123,7 +123,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'all' sample.yml
yq 'all' sample.yml
```
will output
```yaml
@ -142,7 +142,7 @@ b:
```
then
```bash
yq eval '.[] |= all_c(tag == "!!str")' sample.yml
yq '.[] |= all_c(tag == "!!str")' sample.yml
```
will output
```yaml
@ -153,7 +153,7 @@ b: false
## Not true is false
Running
```bash
yq eval --null-input 'true | not'
yq --null-input 'true | not'
```
will output
```yaml
@ -163,7 +163,7 @@ false
## Not false is true
Running
```bash
yq eval --null-input 'false | not'
yq --null-input 'false | not'
```
will output
```yaml
@ -173,7 +173,7 @@ true
## String values considered to be true
Running
```bash
yq eval --null-input '"cat" | not'
yq --null-input '"cat" | not'
```
will output
```yaml
@ -183,7 +183,7 @@ false
## Empty string value considered to be true
Running
```bash
yq eval --null-input '"" | not'
yq --null-input '"" | not'
```
will output
```yaml
@ -193,7 +193,7 @@ false
## Numbers are considered to be true
Running
```bash
yq eval --null-input '1 | not'
yq --null-input '1 | not'
```
will output
```yaml
@ -203,7 +203,7 @@ false
## Zero is considered to be true
Running
```bash
yq eval --null-input '0 | not'
yq --null-input '0 | not'
```
will output
```yaml
@ -213,7 +213,7 @@ false
## Null is considered to be false
Running
```bash
yq eval --null-input '~ | not'
yq --null-input '~ | not'
```
will output
```yaml

View File

@ -6,7 +6,7 @@ This creates an array using the expression between the square brackets.
## Collect empty
Running
```bash
yq eval --null-input '[]'
yq --null-input '[]'
```
will output
```yaml
@ -16,7 +16,7 @@ will output
## Collect single
Running
```bash
yq eval --null-input '["cat"]'
yq --null-input '["cat"]'
```
will output
```yaml
@ -31,7 +31,7 @@ b: dog
```
then
```bash
yq eval '[.a, .b]' sample.yml
yq '[.a, .b]' sample.yml
```
will output
```yaml

View File

@ -17,7 +17,7 @@ a: cat
```
then
```bash
yq eval '.a lineComment="single"' sample.yml
yq '.a lineComment="single"' sample.yml
```
will output
```yaml
@ -32,7 +32,7 @@ b: dog
```
then
```bash
yq eval '.. lineComment |= .' sample.yml
yq '.. lineComment |= .' sample.yml
```
will output
```yaml
@ -47,7 +47,7 @@ a: cat
```
then
```bash
yq eval '. headComment="single"' sample.yml
yq '. headComment="single"' sample.yml
```
will output
```yaml
@ -63,7 +63,7 @@ a: cat
```
then
```bash
yq eval '. footComment=.a' sample.yml
yq '. footComment=.a' sample.yml
```
will output
```yaml
@ -80,7 +80,7 @@ b: dog # leave this
```
then
```bash
yq eval '.a lineComment=""' sample.yml
yq '.a lineComment=""' sample.yml
```
will output
```yaml
@ -99,7 +99,7 @@ b: # key comment
```
then
```bash
yq eval '... comments=""' sample.yml
yq '... comments=""' sample.yml
```
will output
```yaml
@ -114,7 +114,7 @@ a: cat # meow
```
then
```bash
yq eval '.a | lineComment' sample.yml
yq '.a | lineComment' sample.yml
```
will output
```yaml
@ -132,7 +132,7 @@ a: cat # meow
```
then
```bash
yq eval '. | headComment' sample.yml
yq '. | headComment' sample.yml
```
will output
```yaml
@ -151,7 +151,7 @@ a: cat # meow
```
then
```bash
yq eval 'headComment' sample.yml
yq 'headComment' sample.yml
```
will output
```yaml
@ -171,7 +171,7 @@ a: cat # meow
```
then
```bash
yq eval '. | footComment' sample.yml
yq '. | footComment' sample.yml
```
will output
```yaml

View File

@ -13,7 +13,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'contains(["baz", "bar"])' sample.yml
yq 'contains(["baz", "bar"])' sample.yml
```
will output
```yaml
@ -32,7 +32,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'contains({"bar": [{"barp": 12}]})' sample.yml
yq 'contains({"bar": [{"barp": 12}]})' sample.yml
```
will output
```yaml
@ -51,7 +51,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'contains({"foo": 12, "bar": [{"barp": 15}]})' sample.yml
yq 'contains({"foo": 12, "bar": [{"barp": 15}]})' sample.yml
```
will output
```yaml
@ -65,7 +65,7 @@ foobar
```
then
```bash
yq eval 'contains("bar")' sample.yml
yq 'contains("bar")' sample.yml
```
will output
```yaml
@ -79,7 +79,7 @@ meow
```
then
```bash
yq eval 'contains("meow")' sample.yml
yq 'contains("meow")' sample.yml
```
will output
```yaml

View File

@ -5,7 +5,7 @@ This is used to construct objects (or maps). This can be used against existing y
## Collect empty object
Running
```bash
yq eval --null-input '{}'
yq --null-input '{}'
```
will output
```yaml
@ -19,7 +19,7 @@ name: Mike
```
then
```bash
yq eval '{"wrap": .}' sample.yml
yq '{"wrap": .}' sample.yml
```
will output
```yaml
@ -37,7 +37,7 @@ pets:
```
then
```bash
yq eval '{.name: .pets.[]}' sample.yml
yq '{.name: .pets.[]}' sample.yml
```
will output
```yaml
@ -60,7 +60,7 @@ pets:
```
then
```bash
yq eval '{.name: .pets.[]}' sample.yml
yq '{.name: .pets.[]}' sample.yml
```
will output
```yaml
@ -73,7 +73,7 @@ Rosey: sheep
## Creating yaml from scratch
Running
```bash
yq eval --null-input '{"wrap": "frog"}'
yq --null-input '{"wrap": "frog"}'
```
will output
```yaml

View File

@ -10,7 +10,7 @@ b: dog
```
then
```bash
yq eval 'del(.b)' sample.yml
yq 'del(.b)' sample.yml
```
will output
```yaml
@ -26,7 +26,7 @@ a:
```
then
```bash
yq eval 'del(.a.a1)' sample.yml
yq 'del(.a.a1)' sample.yml
```
will output
```yaml
@ -43,7 +43,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'del(.[1])' sample.yml
yq 'del(.[1])' sample.yml
```
will output
```yaml
@ -59,7 +59,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'del(.[0].a)' sample.yml
yq 'del(.[0].a)' sample.yml
```
will output
```yaml
@ -74,7 +74,7 @@ b: dog
```
then
```bash
yq eval 'del(.c)' sample.yml
yq 'del(.c)' sample.yml
```
will output
```yaml
@ -91,7 +91,7 @@ c: bat
```
then
```bash
yq eval 'del( .[] | select(. == "*at") )' sample.yml
yq 'del( .[] | select(. == "*at") )' sample.yml
```
will output
```yaml
@ -109,7 +109,7 @@ a:
```
then
```bash
yq eval 'del(.. | select(has("name")).name)' sample.yml
yq 'del(.. | select(has("name")).name)' sample.yml
```
will output
```yaml

View File

@ -11,7 +11,7 @@ a: frog
```
then
```bash
yq eval '.a | documentIndex' sample.yml
yq '.a | documentIndex' sample.yml
```
will output
```yaml
@ -29,7 +29,7 @@ a: frog
```
then
```bash
yq eval '.a | di' sample.yml
yq '.a | di' sample.yml
```
will output
```yaml
@ -47,7 +47,7 @@ a: frog
```
then
```bash
yq eval 'select(documentIndex == 1)' sample.yml
yq 'select(documentIndex == 1)' sample.yml
```
will output
```yaml
@ -63,7 +63,7 @@ a: frog
```
then
```bash
yq eval 'select(di == 1)' sample.yml
yq 'select(di == 1)' sample.yml
```
will output
```yaml
@ -79,7 +79,7 @@ a: frog
```
then
```bash
yq eval '.a | ({"match": ., "doc": documentIndex})' sample.yml
yq '.a | ({"match": ., "doc": documentIndex})' sample.yml
```
will output
```yaml

View File

@ -30,7 +30,7 @@ a:
```
then
```bash
yq eval '.b = (.a | to_json)' sample.yml
yq '.b = (.a | to_json)' sample.yml
```
will output
```yaml
@ -52,7 +52,7 @@ a:
```
then
```bash
yq eval '.b = (.a | to_json(0))' sample.yml
yq '.b = (.a | to_json(0))' sample.yml
```
will output
```yaml
@ -71,7 +71,7 @@ a:
```
then
```bash
yq eval '.b = (.a | @json)' sample.yml
yq '.b = (.a | @json)' sample.yml
```
will output
```yaml
@ -89,7 +89,7 @@ a: '{"cool":"thing"}'
```
then
```bash
yq eval '.a | from_json | ... style=""' sample.yml
yq '.a | from_json | ... style=""' sample.yml
```
will output
```yaml
@ -104,7 +104,7 @@ a:
```
then
```bash
yq eval '.b = (.a | @props)' sample.yml
yq '.b = (.a | @props)' sample.yml
```
will output
```yaml
@ -125,7 +125,7 @@ a:
```
then
```bash
yq eval '.b = (.a | to_yaml)' sample.yml
yq '.b = (.a | to_yaml)' sample.yml
```
will output
```yaml
@ -148,7 +148,7 @@ a:
```
then
```bash
yq eval '.b = (.a | to_yaml(8))' sample.yml
yq '.b = (.a | to_yaml(8))' sample.yml
```
will output
```yaml
@ -167,7 +167,7 @@ a: 'foo: bar'
```
then
```bash
yq eval '.b = (.a | from_yaml)' sample.yml
yq '.b = (.a | from_yaml)' sample.yml
```
will output
```yaml
@ -186,7 +186,7 @@ a: |
```
then
```bash
yq eval '.a |= (from_yaml | .foo = "cat" | to_yaml)' sample.yml
yq '.a |= (from_yaml | .foo = "cat" | to_yaml)' sample.yml
```
will output
```yaml
@ -202,7 +202,7 @@ a: 'foo: bar'
```
then
```bash
yq eval '.a |= (from_yaml | .foo = "cat" | to_yaml)' sample.yml
yq '.a |= (from_yaml | .foo = "cat" | to_yaml)' sample.yml
```
will output
```yaml
@ -221,7 +221,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '@csv' sample.yml
yq '@csv' sample.yml
```
will output
```yaml
@ -242,7 +242,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '@csv' sample.yml
yq '@csv' sample.yml
```
will output
```yaml
@ -266,7 +266,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '@tsv' sample.yml
yq '@tsv' sample.yml
```
will output
```yaml
@ -284,7 +284,7 @@ a:
```
then
```bash
yq eval '.a | to_xml' sample.yml
yq '.a | to_xml' sample.yml
```
will output
```yaml
@ -304,7 +304,7 @@ a:
```
then
```bash
yq eval '.a | @xml' sample.yml
yq '.a | @xml' sample.yml
```
will output
```yaml
@ -322,7 +322,7 @@ a:
```
then
```bash
yq eval '{"cat": .a | to_xml(1)}' sample.yml
yq '{"cat": .a | to_xml(1)}' sample.yml
```
will output
```yaml
@ -339,7 +339,7 @@ a: <foo>bar</foo>
```
then
```bash
yq eval '.b = (.a | from_xml)' sample.yml
yq '.b = (.a | from_xml)' sample.yml
```
will output
```yaml

View File

@ -10,7 +10,7 @@ b: 2
```
then
```bash
yq eval 'to_entries' sample.yml
yq 'to_entries' sample.yml
```
will output
```yaml
@ -28,7 +28,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'to_entries' sample.yml
yq 'to_entries' sample.yml
```
will output
```yaml
@ -45,7 +45,7 @@ null
```
then
```bash
yq eval 'to_entries' sample.yml
yq 'to_entries' sample.yml
```
will output
```yaml
@ -59,7 +59,7 @@ b: 2
```
then
```bash
yq eval 'to_entries | from_entries' sample.yml
yq 'to_entries | from_entries' sample.yml
```
will output
```yaml
@ -77,7 +77,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'to_entries | from_entries' sample.yml
yq 'to_entries | from_entries' sample.yml
```
will output
```yaml
@ -93,7 +93,7 @@ b: 2
```
then
```bash
yq eval 'with_entries(.key |= "KEY_" + .)' sample.yml
yq 'with_entries(.key |= "KEY_" + .)' sample.yml
```
will output
```yaml
@ -111,7 +111,7 @@ c:
```
then
```bash
yq eval 'with_entries(select(.value | has("b")))' sample.yml
yq 'with_entries(select(.value | has("b")))' sample.yml
```
will output
```yaml

View File

@ -13,14 +13,14 @@ To replace environment variables across all values in a document, `envsubst` can
as follows:
```bash
yq eval '(.. | select(tag == "!!str")) |= envsubst' file.yaml
yq '(.. | select(tag == "!!str")) |= envsubst' file.yaml
```
## Read string environment variable
Running
```bash
myenv="cat meow" yq eval --null-input '.a = env(myenv)'
myenv="cat meow" yq --null-input '.a = env(myenv)'
```
will output
```yaml
@ -30,7 +30,7 @@ a: cat meow
## Read boolean environment variable
Running
```bash
myenv="true" yq eval --null-input '.a = env(myenv)'
myenv="true" yq --null-input '.a = env(myenv)'
```
will output
```yaml
@ -40,7 +40,7 @@ a: true
## Read numeric environment variable
Running
```bash
myenv="12" yq eval --null-input '.a = env(myenv)'
myenv="12" yq --null-input '.a = env(myenv)'
```
will output
```yaml
@ -50,7 +50,7 @@ a: 12
## Read yaml environment variable
Running
```bash
myenv="{b: fish}" yq eval --null-input '.a = env(myenv)'
myenv="{b: fish}" yq --null-input '.a = env(myenv)'
```
will output
```yaml
@ -60,7 +60,7 @@ a: {b: fish}
## Read boolean environment variable as a string
Running
```bash
myenv="true" yq eval --null-input '.a = strenv(myenv)'
myenv="true" yq --null-input '.a = strenv(myenv)'
```
will output
```yaml
@ -70,7 +70,7 @@ a: "true"
## Read numeric environment variable as a string
Running
```bash
myenv="12" yq eval --null-input '.a = strenv(myenv)'
myenv="12" yq --null-input '.a = strenv(myenv)'
```
will output
```yaml
@ -85,7 +85,7 @@ dog: woof
```
then
```bash
myenv="cat" yq eval '.[env(myenv)]' sample.yml
myenv="cat" yq '.[env(myenv)]' sample.yml
```
will output
```yaml
@ -95,7 +95,7 @@ meow
## Replace strings with envsubst
Running
```bash
myenv="cat" yq eval --null-input '"the ${myenv} meows" | envsubst'
myenv="cat" yq --null-input '"the ${myenv} meows" | envsubst'
```
will output
```yaml
@ -105,7 +105,7 @@ the cat meows
## Replace strings with envsubst, missing variables
Running
```bash
myenv="cat" yq eval --null-input '"the ${myenvnonexisting} meows" | envsubst'
myenv="cat" yq --null-input '"the ${myenvnonexisting} meows" | envsubst'
```
will output
```yaml
@ -115,7 +115,7 @@ the meows
## Replace strings with envsubst, missing variables with defaults
Running
```bash
myenv="cat" yq eval --null-input '"the ${myenvnonexisting-dog} meows" | envsubst'
myenv="cat" yq --null-input '"the ${myenvnonexisting-dog} meows" | envsubst'
```
will output
```yaml
@ -129,7 +129,7 @@ v: ${myenv}
```
then
```bash
myenv="cat meow" yq eval '.v |= envsubst' sample.yml
myenv="cat meow" yq '.v |= envsubst' sample.yml
```
will output
```yaml

View File

@ -21,7 +21,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[] | (. == "*at")' sample.yml
yq '.[] | (. == "*at")' sample.yml
```
will output
```yaml
@ -39,7 +39,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[] | (. != "*at")' sample.yml
yq '.[] | (. != "*at")' sample.yml
```
will output
```yaml
@ -57,7 +57,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[] | (. == 4)' sample.yml
yq '.[] | (. == 4)' sample.yml
```
will output
```yaml
@ -75,7 +75,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[] | (. != 4)' sample.yml
yq '.[] | (. != 4)' sample.yml
```
will output
```yaml
@ -87,7 +87,7 @@ true
## Match nulls
Running
```bash
yq eval --null-input 'null == ~'
yq --null-input 'null == ~'
```
will output
```yaml
@ -101,7 +101,7 @@ a: frog
```
then
```bash
yq eval 'select(.b != "thing")' sample.yml
yq 'select(.b != "thing")' sample.yml
```
will output
```yaml
@ -115,7 +115,7 @@ a: frog
```
then
```bash
yq eval 'select(.b == .c)' sample.yml
yq 'select(.b == .c)' sample.yml
```
will output
```yaml

View File

@ -17,7 +17,7 @@ a: cat
```
then
```bash
yq eval 'filename' sample.yml
yq 'filename' sample.yml
```
will output
```yaml
@ -31,7 +31,7 @@ a: cat
```
then
```bash
yq eval 'fileIndex' sample.yml
yq 'fileIndex' sample.yml
```
will output
```yaml
@ -65,7 +65,7 @@ a: cat
```
then
```bash
yq eval 'fi' sample.yml
yq 'fi' sample.yml
```
will output
```yaml

View File

@ -12,7 +12,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'flatten' sample.yml
yq 'flatten' sample.yml
```
will output
```yaml
@ -30,7 +30,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'flatten(1)' sample.yml
yq 'flatten(1)' sample.yml
```
will output
```yaml
@ -46,7 +46,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'flatten' sample.yml
yq 'flatten' sample.yml
```
will output
```yaml
@ -61,7 +61,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'flatten' sample.yml
yq 'flatten' sample.yml
```
will output
```yaml

View File

@ -14,7 +14,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'group_by(.foo)' sample.yml
yq 'group_by(.foo)' sample.yml
```
will output
```yaml
@ -40,7 +40,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'group_by(.foo)' sample.yml
yq 'group_by(.foo)' sample.yml
```
will output
```yaml

View File

@ -12,7 +12,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[] | has("a")' sample.yml
yq '.[] | has("a")' sample.yml
```
will output
```yaml
@ -36,7 +36,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[] | select(.a.b | has("c"))' sample.yml
yq '.[] | select(.a.b | has("c"))' sample.yml
```
will output
```yaml
@ -57,7 +57,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[] | has(1)' sample.yml
yq '.[] | has(1)' sample.yml
```
will output
```yaml

View File

@ -5,7 +5,7 @@
yq [eval/eval-all] [expression] files..
eval/e - Apply the expression to each document in each yaml file in sequence
eval/e - (default) Apply the expression to each document in each yaml file in sequence
eval-all/ea - Loads all yaml documents of all yaml files and runs expression once
@ -18,32 +18,33 @@ This documentation is also available at https://mikefarah.gitbook.io/yq/
## Read a value:
```bash
yq e '.a.b[0].c' file.yaml
yq '.a.b[0].c' file.yaml
```
## Pipe from STDIN:
```bash
cat file.yaml | yq e '.a.b[0].c' -
cat file.yaml | yq '.a.b[0].c'
```
## Update a yaml file, inplace
```bash
yq e -i '.a.b[0].c = "cool"' file.yaml
yq -i '.a.b[0].c = "cool"' file.yaml
```
## Update using environment variables
```bash
NAME=mike yq e -i '.a.b[0].c = strenv(NAME)' file.yaml
NAME=mike yq -i '.a.b[0].c = strenv(NAME)' file.yaml
```
## Merge multiple files
```
yq ea '. as $item ireduce ({}; . * $item )' path/to/*.yml
```
Note the use of `ea` to evaluate all files at once (instead of in sequence.)
## Multiple updates to a yaml file
```bash
yq e -i '
yq -i '
.a.b[0].c = "cool" |
.x.y.z = "foobar" |
.person.name = strenv(NAME)

View File

@ -13,6 +13,6 @@ To replace environment variables across all values in a document, `envsubst` can
as follows:
```bash
yq eval '(.. | select(tag == "!!str")) |= envsubst' file.yaml
yq '(.. | select(tag == "!!str")) |= envsubst' file.yaml
```

View File

@ -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:
```bash
yq eval '.. style= "flow"' file.yaml
yq '.. style= "flow"' file.yaml
```
## match values and map keys form `...`
@ -17,5 +17,5 @@ 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:
```bash
yq eval '... style= "flow"' file.yaml
yq '... style= "flow"' file.yaml
```

View File

@ -5,7 +5,9 @@ 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:
```bash
yq eval -i -P 'sort_keys(..)' file1.yml
yq eval -i -P 'sort_keys(..)' file2.yml
yq -i -P 'sort_keys(..)' file1.yml
yq -i -P 'sort_keys(..)' 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.

View File

@ -17,13 +17,13 @@ a: |
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
```
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: |
cat
```
@ -31,7 +31,7 @@ a: |
As well as having multiline expressions:
```
m="cat
" yq e -n '.a = strenv(m)'
" yq -n '.a = strenv(m)'
a: |
cat
```
@ -40,5 +40,5 @@ Similarly, if you're trying to set the content from a file, and want a trailing
```
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
```

View File

@ -10,7 +10,7 @@ cat: meow
```
then
```bash
yq eval 'keys' sample.yml
yq 'keys' sample.yml
```
will output
```yaml
@ -26,7 +26,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'keys' sample.yml
yq 'keys' sample.yml
```
will output
```yaml
@ -43,7 +43,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[1] | key' sample.yml
yq '.[1] | key' sample.yml
```
will output
```yaml
@ -57,7 +57,7 @@ a: thing
```
then
```bash
yq eval '.a | key' sample.yml
yq '.a | key' sample.yml
```
will output
```yaml
@ -71,7 +71,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'key' sample.yml
yq 'key' sample.yml
```
will output
```yaml
@ -86,7 +86,7 @@ a:
```
then
```bash
yq eval '(.a.x | key) = "meow"' sample.yml
yq '(.a.x | key) = "meow"' sample.yml
```
will output
```yaml
@ -105,7 +105,7 @@ a:
```
then
```bash
yq eval '.a.x | key | headComment' sample.yml
yq '.a.x | key | headComment' sample.yml
```
will output
```yaml

View File

@ -11,7 +11,7 @@ a: cat
```
then
```bash
yq eval '.a | length' sample.yml
yq '.a | length' sample.yml
```
will output
```yaml
@ -25,7 +25,7 @@ a: null
```
then
```bash
yq eval '.a | length' sample.yml
yq '.a | length' sample.yml
```
will output
```yaml
@ -42,7 +42,7 @@ c: dog
```
then
```bash
yq eval 'length' sample.yml
yq 'length' sample.yml
```
will output
```yaml
@ -61,7 +61,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'length' sample.yml
yq 'length' sample.yml
```
will output
```yaml

View File

@ -20,7 +20,7 @@ myFile: ../../examples/thing.yml
```
then
```bash
yq eval 'load(.myFile)' sample.yml
yq 'load(.myFile)' sample.yml
```
will output
```yaml
@ -38,7 +38,7 @@ something:
```
then
```bash
yq eval '.something |= load("../../examples/" + .file)' sample.yml
yq '.something |= load("../../examples/" + .file)' sample.yml
```
will output
```yaml
@ -60,7 +60,7 @@ over:
```
then
```bash
yq eval '(.. | select(has("file"))) |= load("../../examples/" + .file)' sample.yml
yq '(.. | select(has("file"))) |= load("../../examples/" + .file)' sample.yml
```
will output
```yaml
@ -83,7 +83,7 @@ something:
```
then
```bash
yq eval '.something |= strload("../../examples/" + .file)' sample.yml
yq '.something |= strload("../../examples/" + .file)' sample.yml
```
will output
```yaml

View File

@ -11,7 +11,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'map(. + 1)' sample.yml
yq 'map(. + 1)' sample.yml
```
will output
```yaml
@ -29,7 +29,7 @@ c: 3
```
then
```bash
yq eval 'map_values(. + 1)' sample.yml
yq 'map_values(. + 1)' sample.yml
```
will output
```yaml

View File

@ -30,7 +30,7 @@ b: 4
```
then
```bash
yq eval '.a *= .b' sample.yml
yq '.a *= .b' sample.yml
```
will output
```yaml
@ -51,7 +51,7 @@ b:
```
then
```bash
yq eval '.a * .b' sample.yml
yq '.a * .b' sample.yml
```
will output
```yaml
@ -74,7 +74,7 @@ b:
```
then
```bash
yq eval '. * {"a":.b}' sample.yml
yq '. * {"a":.b}' sample.yml
```
will output
```yaml
@ -98,7 +98,7 @@ b:
```
then
```bash
yq eval '. * {"a":.b}' sample.yml
yq '. * {"a":.b}' sample.yml
```
will output
```yaml
@ -121,7 +121,7 @@ b:
```
then
```bash
yq eval '. * {"a":.b}' sample.yml
yq '. * {"a":.b}' sample.yml
```
will output
```yaml
@ -147,7 +147,7 @@ b:
```
then
```bash
yq eval '.a *? .b' sample.yml
yq '.a *? .b' sample.yml
```
will output
```yaml
@ -167,7 +167,7 @@ b:
```
then
```bash
yq eval '.a *n .b' sample.yml
yq '.a *n .b' sample.yml
```
will output
```yaml
@ -194,7 +194,7 @@ b:
```
then
```bash
yq eval '.a *+ .b' sample.yml
yq '.a *+ .b' sample.yml
```
will output
```yaml
@ -224,7 +224,7 @@ b:
```
then
```bash
yq eval '.a *?+ .b' sample.yml
yq '.a *?+ .b' sample.yml
```
will output
```yaml
@ -251,7 +251,7 @@ b:
```
then
```bash
yq eval '.a *d .b' sample.yml
yq '.a *d .b' sample.yml
```
will output
```yaml
@ -331,7 +331,7 @@ b: dog
```
then
```bash
yq eval '. * {"a": {"c": .a}}' sample.yml
yq '. * {"a": {"c": .a}}' sample.yml
```
will output
```yaml
@ -352,7 +352,7 @@ c:
```
then
```bash
yq eval '.c * .b' sample.yml
yq '.c * .b' sample.yml
```
will output
```yaml
@ -372,7 +372,7 @@ c:
```
then
```bash
yq eval '.c * .a' sample.yml
yq '.c * .a' sample.yml
```
will output
```yaml
@ -404,7 +404,7 @@ foobar:
```
then
```bash
yq eval '.foobar * .foobarList' sample.yml
yq '.foobar * .foobarList' sample.yml
```
will output
```yaml
@ -426,7 +426,7 @@ b: !goat 3
```
then
```bash
yq eval '.a = .a * .b' sample.yml
yq '.a = .a * .b' sample.yml
```
will output
```yaml
@ -446,7 +446,7 @@ b: !goat
```
then
```bash
yq eval '.a = .a * .b' sample.yml
yq '.a = .a * .b' sample.yml
```
will output
```yaml

View File

@ -10,7 +10,7 @@ a:
```
then
```bash
yq eval '.a.nested | parent' sample.yml
yq '.a.nested | parent' sample.yml
```
will output
```yaml
@ -29,7 +29,7 @@ b:
```
then
```bash
yq eval '.. | select(. == "banana") | parent' sample.yml
yq '.. | select(. == "banana") | parent' sample.yml
```
will output
```yaml
@ -44,7 +44,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'parent' sample.yml
yq 'parent' sample.yml
```
will output
```yaml

View File

@ -12,7 +12,7 @@ a:
```
then
```bash
yq eval '.a.b | path' sample.yml
yq '.a.b | path' sample.yml
```
will output
```yaml
@ -28,7 +28,7 @@ a:
```
then
```bash
yq eval '.a.b | path | .[-1]' sample.yml
yq '.a.b | path | .[-1]' sample.yml
```
will output
```yaml
@ -44,7 +44,7 @@ a:
```
then
```bash
yq eval '.a.[] | select(. == "dog") | path' sample.yml
yq '.a.[] | select(. == "dog") | path' sample.yml
```
will output
```yaml
@ -61,7 +61,7 @@ a:
```
then
```bash
yq eval '.a.[] | select(. == "dog") | path | .[-1]' sample.yml
yq '.a.[] | select(. == "dog") | path | .[-1]' sample.yml
```
will output
```yaml
@ -78,7 +78,7 @@ a:
```
then
```bash
yq eval '.a[] | select(. == "*og") | [{"path":path, "value":.}]' sample.yml
yq '.a[] | select(. == "*og") | [{"path":path, "value":.}]' sample.yml
```
will output
```yaml

View File

@ -10,7 +10,7 @@ a:
```
then
```bash
yq eval '.a | .b' sample.yml
yq '.a | .b' sample.yml
```
will output
```yaml
@ -26,7 +26,7 @@ c: same
```
then
```bash
yq eval '.a = "cat" | .b = "dog"' sample.yml
yq '.a = "cat" | .b = "dog"' sample.yml
```
will output
```yaml

View File

@ -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:
```bash
yq eval '.. style= "flow"' file.yaml
yq '.. style= "flow"' file.yaml
```
## 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:
```bash
yq eval '... style= "flow"' file.yaml
yq '... style= "flow"' file.yaml
```
## Recurse map (values only)
Given a sample.yml file of:
@ -26,7 +26,7 @@ a: frog
```
then
```bash
yq eval '..' sample.yml
yq '..' sample.yml
```
will output
```yaml
@ -47,7 +47,7 @@ a:
```
then
```bash
yq eval '[.. | select(has("name"))]' sample.yml
yq '[.. | select(has("name"))]' sample.yml
```
will output
```yaml
@ -70,7 +70,7 @@ a:
```
then
```bash
yq eval '.. | select(. == "frog")' sample.yml
yq '.. | select(. == "frog")' sample.yml
```
will output
```yaml
@ -87,7 +87,7 @@ a: frog
```
then
```bash
yq eval '...' sample.yml
yq '...' sample.yml
```
will output
```yaml
@ -105,7 +105,7 @@ b: *cat
```
then
```bash
yq eval '[..]' sample.yml
yq '[..]' sample.yml
```
will output
```yaml
@ -142,7 +142,7 @@ foobar:
```
then
```bash
yq eval '.foobar | [..]' sample.yml
yq '.foobar | [..]' sample.yml
```
will output
```yaml

View File

@ -31,7 +31,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[] as $item ireduce (0; . + $item)' sample.yml
yq '.[] as $item ireduce (0; . + $item)' sample.yml
```
will output
```yaml
@ -67,7 +67,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[] as $item ireduce ({}; .[$item | .name] = ($item | .has) )' sample.yml
yq '.[] as $item ireduce ({}; .[$item | .name] = ($item | .has) )' sample.yml
```
will output
```yaml

View File

@ -11,7 +11,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[] | select(. == "*at")' sample.yml
yq '.[] | select(. == "*at")' sample.yml
```
will output
```yaml
@ -28,7 +28,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[] | select(. == "go*")' sample.yml
yq '.[] | select(. == "go*")' sample.yml
```
will output
```yaml
@ -46,7 +46,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[] | select(. == "*go*")' sample.yml
yq '.[] | select(. == "*go*")' sample.yml
```
will output
```yaml
@ -67,7 +67,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[] | select(test("[a-zA-Z]+_[0-9]$"))' sample.yml
yq '.[] | select(test("[a-zA-Z]+_[0-9]$"))' sample.yml
```
will output
```yaml
@ -84,7 +84,7 @@ horse: dog
```
then
```bash
yq eval '.[] | select(. == "cat" or test("og$"))' sample.yml
yq '.[] | select(. == "cat" or test("og$"))' sample.yml
```
will output
```yaml
@ -101,7 +101,7 @@ game: poker
```
then
```bash
yq eval 'with_entries(select(.key | test("ame$")))' sample.yml
yq 'with_entries(select(.key | test("ame$")))' sample.yml
```
will output
```yaml
@ -121,7 +121,7 @@ a:
```
then
```bash
yq eval '(.a.[] | select(. == "cat" or . == "goat")) |= "rabbit"' sample.yml
yq '(.a.[] | select(. == "cat" or . == "goat")) |= "rabbit"' sample.yml
```
will output
```yaml

View File

@ -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:
```bash
yq eval -i -P 'sort_keys(..)' file1.yml
yq eval -i -P 'sort_keys(..)' file2.yml
yq -i -P 'sort_keys(..)' file1.yml
yq -i -P 'sort_keys(..)' 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
Given a sample.yml file of:
```yaml
@ -19,7 +21,7 @@ b: bing
```
then
```bash
yq eval 'sort_keys(.)' sample.yml
yq 'sort_keys(.)' sample.yml
```
will output
```yaml
@ -49,7 +51,7 @@ aParent:
```
then
```bash
yq eval 'sort_keys(..)' sample.yml
yq 'sort_keys(..)' sample.yml
```
will output
```yaml

View File

@ -13,7 +13,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'sort_by(.a)' sample.yml
yq 'sort_by(.a)' sample.yml
```
will output
```yaml
@ -32,7 +32,7 @@ cool:
```
then
```bash
yq eval '.cool |= sort_by(.a)' sample.yml
yq '.cool |= sort_by(.a)' sample.yml
```
will output
```yaml
@ -54,7 +54,7 @@ cool:
```
then
```bash
yq eval '.cool |= sort_by(keys | .[0])' sample.yml
yq '.cool |= sort_by(keys | .[0])' sample.yml
```
will output
```yaml
@ -80,7 +80,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'sort_by(.a)' sample.yml
yq 'sort_by(.a)' sample.yml
```
will output
```yaml
@ -103,7 +103,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'sort_by(.a)' sample.yml
yq 'sort_by(.a)' sample.yml
```
will output
```yaml
@ -125,7 +125,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'sort' sample.yml
yq 'sort' sample.yml
```
will output
```yaml

View File

@ -5,7 +5,7 @@ This operator splits all matches into separate documents
## Split empty
Running
```bash
yq eval --null-input 'splitDoc'
yq --null-input 'splitDoc'
```
will output
```yaml
@ -20,7 +20,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[] | splitDoc' sample.yml
yq '.[] | splitDoc' sample.yml
```
will output
```yaml

View File

@ -17,13 +17,13 @@ a: |
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
```
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: |
cat
```
@ -31,7 +31,7 @@ a: |
As well as having multiline expressions:
```
m="cat
" yq e -n '.a = strenv(m)'
" yq -n '.a = strenv(m)'
a: |
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)
output=$output ./yq e '.data.values = strenv(output)' first.yml
output=$output ./yq '.data.values = strenv(output)' first.yml
```
## Join strings
@ -54,7 +54,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'join("; ")' sample.yml
yq 'join("; ")' sample.yml
```
will output
```yaml
@ -68,7 +68,7 @@ foo bar foo
```
then
```bash
yq eval 'match("foo")' sample.yml
yq 'match("foo")' sample.yml
```
will output
```yaml
@ -85,7 +85,7 @@ foo bar FOO
```
then
```bash
yq eval '[match("(?i)foo"; "g")]' sample.yml
yq '[match("(?i)foo"; "g")]' sample.yml
```
will output
```yaml
@ -106,7 +106,7 @@ abc abc
```
then
```bash
yq eval '[match("(abc)+"; "g")]' sample.yml
yq '[match("(abc)+"; "g")]' sample.yml
```
will output
```yaml
@ -133,7 +133,7 @@ foo bar foo foo foo
```
then
```bash
yq eval '[match("foo (?P<bar123>bar)? foo"; "g")]' sample.yml
yq '[match("foo (?P<bar123>bar)? foo"; "g")]' sample.yml
```
will output
```yaml
@ -162,7 +162,7 @@ xyzzy-14
```
then
```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
```yaml
@ -177,7 +177,7 @@ cat cat
```
then
```bash
yq eval 'match("cat")' sample.yml
yq 'match("cat")' sample.yml
```
will output
```yaml
@ -194,7 +194,7 @@ cat cat
```
then
```bash
yq eval '[match("cat"; "g")]' sample.yml
yq '[match("cat"; "g")]' sample.yml
```
will output
```yaml
@ -218,7 +218,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[] | test("at")' sample.yml
yq '.[] | test("at")' sample.yml
```
will output
```yaml
@ -236,7 +236,7 @@ a: dogs are great
```
then
```bash
yq eval '.a |= sub("dogs", "cats")' sample.yml
yq '.a |= sub("dogs", "cats")' sample.yml
```
will output
```yaml
@ -254,7 +254,7 @@ b: heat
```
then
```bash
yq eval '.[] |= sub("(a)", "${1}r")' sample.yml
yq '.[] |= sub("(a)", "${1}r")' sample.yml
```
will output
```yaml
@ -269,7 +269,7 @@ cat; meow; 1; ; true
```
then
```bash
yq eval 'split("; ")' sample.yml
yq 'split("; ")' sample.yml
```
will output
```yaml
@ -287,7 +287,7 @@ word
```
then
```bash
yq eval 'split("; ")' sample.yml
yq 'split("; ")' sample.yml
```
will output
```yaml

View File

@ -11,7 +11,7 @@ a:
```
then
```bash
yq eval '.a.b = "new" | .a.b style="double"' sample.yml
yq '.a.b = "new" | .a.b style="double"' sample.yml
```
will output
```yaml
@ -29,7 +29,7 @@ a:
```
then
```bash
yq eval 'with(.a.b ; . = "new" | . style="double")' sample.yml
yq 'with(.a.b ; . = "new" | . style="double")' sample.yml
```
will output
```yaml
@ -48,7 +48,7 @@ e: true
```
then
```bash
yq eval '.. style="tagged"' sample.yml
yq '.. style="tagged"' sample.yml
```
will output
```yaml
@ -69,7 +69,7 @@ e: true
```
then
```bash
yq eval '.. style="double"' sample.yml
yq '.. style="double"' sample.yml
```
will output
```yaml
@ -89,7 +89,7 @@ e: true
```
then
```bash
yq eval '... style="double"' sample.yml
yq '... style="double"' sample.yml
```
will output
```yaml
@ -109,7 +109,7 @@ e: true
```
then
```bash
yq eval '.. style="single"' sample.yml
yq '.. style="single"' sample.yml
```
will output
```yaml
@ -129,7 +129,7 @@ e: true
```
then
```bash
yq eval '.. style="literal"' sample.yml
yq '.. style="literal"' sample.yml
```
will output
```yaml
@ -153,7 +153,7 @@ e: true
```
then
```bash
yq eval '.. style="folded"' sample.yml
yq '.. style="folded"' sample.yml
```
will output
```yaml
@ -177,7 +177,7 @@ e: true
```
then
```bash
yq eval '.. style="flow"' sample.yml
yq '.. style="flow"' sample.yml
```
will output
```yaml
@ -196,7 +196,7 @@ a: cat
```
then
```bash
yq eval '... style=""' sample.yml
yq '... style=""' sample.yml
```
will output
```yaml
@ -214,7 +214,7 @@ b: double
```
then
```bash
yq eval '.[] style |= .' sample.yml
yq '.[] style |= .' sample.yml
```
will output
```yaml
@ -229,7 +229,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.. | style' sample.yml
yq '.. | style' sample.yml
```
will output
```yaml

View File

@ -5,7 +5,7 @@ You can use subtract to subtract numbers, as well as removing elements from an a
## Array subtraction
Running
```bash
yq eval --null-input '[1,2] - [2,3]'
yq --null-input '[1,2] - [2,3]'
```
will output
```yaml
@ -15,7 +15,7 @@ will output
## Array subtraction with nested array
Running
```bash
yq eval --null-input '[[1], 1, 2] - [[1], 3]'
yq --null-input '[[1], 1, 2] - [[1], 3]'
```
will output
```yaml
@ -34,7 +34,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '. - [{"c": "d", "a": "b"}]' sample.yml
yq '. - [{"c": "d", "a": "b"}]' sample.yml
```
will output
```yaml
@ -51,7 +51,7 @@ b: 4.5
```
then
```bash
yq eval '.a = .a - .b' sample.yml
yq '.a = .a - .b' sample.yml
```
will output
```yaml
@ -69,7 +69,7 @@ b: 4.5
```
then
```bash
yq eval '.a = .a - .b' sample.yml
yq '.a = .a - .b' sample.yml
```
will output
```yaml
@ -87,7 +87,7 @@ b: 4
```
then
```bash
yq eval '.a = .a - .b' sample.yml
yq '.a = .a - .b' sample.yml
```
will output
```yaml
@ -103,7 +103,7 @@ b: 5
```
then
```bash
yq eval '.[] -= 1' sample.yml
yq '.[] -= 1' sample.yml
```
will output
```yaml
@ -121,7 +121,7 @@ b: !goat 1
```
then
```bash
yq eval '.a -= .b' sample.yml
yq '.a -= .b' sample.yml
```
will output
```yaml

View File

@ -13,7 +13,7 @@ f: []
```
then
```bash
yq eval '.. | tag' sample.yml
yq '.. | tag' sample.yml
```
will output
```yaml
@ -32,7 +32,7 @@ a: str
```
then
```bash
yq eval '.a tag = "!!mikefarah"' sample.yml
yq '.a tag = "!!mikefarah"' sample.yml
```
will output
```yaml
@ -49,7 +49,7 @@ e: true
```
then
```bash
yq eval '(.. | select(tag == "!!int")) tag= "!!str"' sample.yml
yq '(.. | select(tag == "!!int")) tag= "!!str"' sample.yml
```
will output
```yaml

View File

@ -10,7 +10,7 @@ a:
```
then
```bash
yq eval '.a' sample.yml
yq '.a' sample.yml
```
will output
```yaml
@ -27,7 +27,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[]' sample.yml
yq '.[]' sample.yml
```
will output
```yaml
@ -44,7 +44,7 @@ cat
```
then
```bash
yq eval '.[]' sample.yml
yq '.[]' sample.yml
```
will output
```yaml
@ -59,7 +59,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.["{}"]' sample.yml
yq '.["{}"]' sample.yml
```
will output
```yaml
@ -75,7 +75,7 @@ a:
```
then
```bash
yq eval '.a["key.withdots"]["another.key"]' sample.yml
yq '.a["key.withdots"]["another.key"]' sample.yml
```
will output
```yaml
@ -91,7 +91,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.["red rabbit"]' sample.yml
yq '.["red rabbit"]' sample.yml
```
will output
```yaml
@ -109,7 +109,7 @@ banana: soft yum
```
then
```bash
yq eval '.[.b]' sample.yml
yq '.[.b]' sample.yml
```
will output
```yaml
@ -125,7 +125,7 @@ c: banana
```
then
```bash
yq eval '.a.b' sample.yml
yq '.a.b' sample.yml
```
will output
```yaml
@ -143,7 +143,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.a?' sample.yml
yq '.a?' sample.yml
```
will output
```yaml
@ -158,7 +158,7 @@ a:
```
then
```bash
yq eval '.a."*a*"' sample.yml
yq '.a."*a*"' sample.yml
```
will output
```yaml
@ -175,7 +175,7 @@ b: *cat
```
then
```bash
yq eval '.b' sample.yml
yq '.b' sample.yml
```
will output
```yaml
@ -191,7 +191,7 @@ b: *cat
```
then
```bash
yq eval '.b[]' sample.yml
yq '.b[]' sample.yml
```
will output
```yaml
@ -207,7 +207,7 @@ b: *cat
```
then
```bash
yq eval '.b.c' sample.yml
yq '.b.c' sample.yml
```
will output
```yaml
@ -223,7 +223,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[0]' sample.yml
yq '.[0]' sample.yml
```
will output
```yaml
@ -237,7 +237,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[1][0]' sample.yml
yq '.[1][0]' sample.yml
```
will output
```yaml
@ -251,7 +251,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[2]' sample.yml
yq '.[2]' sample.yml
```
will output
```yaml
@ -265,7 +265,7 @@ a: b
```
then
```bash
yq eval '.[0]' sample.yml
yq '.[0]' sample.yml
```
will output
```yaml
@ -296,7 +296,7 @@ foobar:
```
then
```bash
yq eval '.foobar.a' sample.yml
yq '.foobar.a' sample.yml
```
will output
```yaml
@ -327,7 +327,7 @@ foobar:
```
then
```bash
yq eval '.foobar.c' sample.yml
yq '.foobar.c' sample.yml
```
will output
```yaml
@ -358,7 +358,7 @@ foobar:
```
then
```bash
yq eval '.foobar.thing' sample.yml
yq '.foobar.thing' sample.yml
```
will output
```yaml
@ -389,7 +389,7 @@ foobar:
```
then
```bash
yq eval '.foobar[]' sample.yml
yq '.foobar[]' sample.yml
```
will output
```yaml
@ -424,7 +424,7 @@ foobar:
```
then
```bash
yq eval '.foobarList.thing' sample.yml
yq '.foobarList.thing' sample.yml
```
will output
```yaml
@ -455,7 +455,7 @@ foobar:
```
then
```bash
yq eval '.foobarList[]' sample.yml
yq '.foobarList[]' sample.yml
```
will output
```yaml
@ -475,7 +475,7 @@ a:
```
then
```bash
yq eval '.a[0, 2]' sample.yml
yq '.a[0, 2]' sample.yml
```
will output
```yaml

View File

@ -5,7 +5,7 @@ This operator is used to combine different results together.
## Combine scalars
Running
```bash
yq eval --null-input '1, true, "cat"'
yq --null-input '1, true, "cat"'
```
will output
```yaml
@ -23,7 +23,7 @@ c: fieldC
```
then
```bash
yq eval '.a, .c' sample.yml
yq '.a, .c' sample.yml
```
will output
```yaml

View File

@ -12,7 +12,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'unique' sample.yml
yq 'unique' sample.yml
```
will output
```yaml
@ -33,7 +33,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'unique' sample.yml
yq 'unique' sample.yml
```
will output
```yaml
@ -53,7 +53,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'unique_by(tag)' sample.yml
yq 'unique_by(tag)' sample.yml
```
will output
```yaml
@ -72,7 +72,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval 'unique_by(.name)' sample.yml
yq 'unique_by(.name)' sample.yml
```
will output
```yaml

View File

@ -11,7 +11,7 @@ a: cat
```
then
```bash
yq eval '.a as $foo | $foo' sample.yml
yq '.a as $foo | $foo' sample.yml
```
will output
```yaml
@ -26,7 +26,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[] as $foo | $foo' sample.yml
yq '.[] as $foo | $foo' sample.yml
```
will output
```yaml
@ -50,7 +50,7 @@ Given a sample.yml file of:
```
then
```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
```yaml
@ -68,7 +68,7 @@ b: b_value
```
then
```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
```yaml
@ -87,7 +87,7 @@ a:
```
then
```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
```yaml

View File

@ -11,7 +11,7 @@ a:
```
then
```bash
yq eval 'with(.a.deeply.nested; . = "newValue" | . style="single")' sample.yml
yq 'with(.a.deeply.nested; . = "newValue" | . style="single")' sample.yml
```
will output
```yaml
@ -30,7 +30,7 @@ a:
```
then
```bash
yq eval 'with(.a.deeply; .nested = "newValue" | .other= "newThing")' sample.yml
yq 'with(.a.deeply; .nested = "newValue" | .other= "newThing")' sample.yml
```
will output
```yaml
@ -51,7 +51,7 @@ myArray:
```
then
```bash
yq eval 'with(.myArray[]; .b = .a + " yum")' sample.yml
yq 'with(.myArray[]; .b = .a + " yum")' sample.yml
```
will output
```yaml

View File

@ -13,7 +13,7 @@ Given a sample.json file of:
```
then
```bash
yq e -P '.' sample.json
yq -P '.' sample.json
```
will output
```yaml
@ -29,7 +29,7 @@ Given a sample.json file of:
```
then
```bash
yq e -P '.' sample.json
yq -P '.' sample.json
```
will output
```yaml
@ -48,7 +48,7 @@ cat: meow
```
then
```bash
yq e -o=json '.' sample.yml
yq -o=json '.' sample.yml
```
will output
```json
@ -64,7 +64,7 @@ cat: meow # this is a comment, and it will be dropped.
```
then
```bash
yq e -o=json -I=0 '.' sample.yml
yq -o=json -I=0 '.' sample.yml
```
will output
```json
@ -78,7 +78,7 @@ cat: meow # this is a comment, and it will be dropped.
```
then
```bash
yq e -o=json '.' sample.yml
yq -o=json '.' sample.yml
```
will output
```json
@ -97,7 +97,7 @@ anotherCat: *ref
```
then
```bash
yq e -o=json '.' sample.yml
yq -o=json '.' sample.yml
```
will output
```json
@ -116,7 +116,7 @@ things: [{stuff: cool}, {whatever: cat}]
```
then
```bash
yq e -o=json -I=0 '.things[]' sample.yml
yq -o=json -I=0 '.things[]' sample.yml
```
will output
```json

View File

@ -20,7 +20,7 @@ Given a sample.xml file of:
```
then
```bash
yq e -p=xml '.' sample.xml
yq -p=xml '.' sample.xml
```
will output
```yaml
@ -44,7 +44,7 @@ Given a sample.xml file of:
```
then
```bash
yq e -p=xml ' (.. | select(tag == "!!str")) |= from_yaml' sample.xml
yq -p=xml ' (.. | select(tag == "!!str")) |= from_yaml' sample.xml
```
will output
```yaml
@ -65,7 +65,7 @@ Given a sample.xml file of:
```
then
```bash
yq e -p=xml '.' sample.xml
yq -p=xml '.' sample.xml
```
will output
```yaml
@ -86,7 +86,7 @@ Given a sample.xml file of:
```
then
```bash
yq e -p=xml '.' sample.xml
yq -p=xml '.' sample.xml
```
will output
```yaml
@ -105,7 +105,7 @@ Given a sample.xml file of:
```
then
```bash
yq e -p=xml '.' sample.xml
yq -p=xml '.' sample.xml
```
will output
```yaml
@ -140,7 +140,7 @@ for x --></x>
```
then
```bash
yq e -p=xml '.' sample.xml
yq -p=xml '.' sample.xml
```
will output
```yaml
@ -168,7 +168,7 @@ cat: purrs
```
then
```bash
yq e -o=xml '.' sample.yml
yq -o=xml '.' sample.yml
```
will output
```xml
@ -185,7 +185,7 @@ pets:
```
then
```bash
yq e -o=xml '.' sample.yml
yq -o=xml '.' sample.yml
```
will output
```xml
@ -207,7 +207,7 @@ cat:
```
then
```bash
yq e -o=xml '.' sample.yml
yq -o=xml '.' sample.yml
```
will output
```xml
@ -228,7 +228,7 @@ cat:
```
then
```bash
yq e -o=xml '.' sample.yml
yq -o=xml '.' sample.yml
```
will output
```xml
@ -252,7 +252,7 @@ cat: # inline_cat
```
then
```bash
yq e -o=xml '.' sample.yml
yq -o=xml '.' sample.yml
```
will output
```xml
@ -288,7 +288,7 @@ for x --></x>
```
then
```bash
yq e -p=xml -o=xml '.' sample.xml
yq -p=xml -o=xml '.' sample.xml
```
will output
```xml

View File

@ -159,7 +159,7 @@ func documentJsonDecodeScenario(t *testing.T, w *bufio.Writer, s formatScenario)
writeOrPanic(w, fmt.Sprintf("```json\n%v\n```\n", s.input))
writeOrPanic(w, "then\n")
writeOrPanic(w, "```bash\nyq e -P '.' sample.json\n```\n")
writeOrPanic(w, "```bash\nyq -P '.' sample.json\n```\n")
writeOrPanic(w, "will output\n")
var output bytes.Buffer
@ -208,9 +208,9 @@ func documentJsonEncodeScenario(w *bufio.Writer, s formatScenario) {
}
if s.indent == 2 {
writeOrPanic(w, fmt.Sprintf("```bash\nyq e -o=json '%v' sample.yml\n```\n", expression))
writeOrPanic(w, fmt.Sprintf("```bash\nyq -o=json '%v' sample.yml\n```\n", expression))
} else {
writeOrPanic(w, fmt.Sprintf("```bash\nyq e -o=json -I=%v '%v' sample.yml\n```\n", s.indent, expression))
writeOrPanic(w, fmt.Sprintf("```bash\nyq -o=json -I=%v '%v' sample.yml\n```\n", s.indent, expression))
}
writeOrPanic(w, "will output\n")

View File

@ -227,7 +227,7 @@ func documentOperatorScenario(t *testing.T, w *bufio.Writer, i interface{}) {
func documentInput(w *bufio.Writer, s expressionScenario) (string, string) {
formattedDoc := ""
formattedDoc2 := ""
command := "eval"
command := ""
envCommand := ""
@ -258,19 +258,19 @@ func documentInput(w *bufio.Writer, s expressionScenario) (string, string) {
writeOrPanic(w, "And another sample another.yml file of:\n")
writeOrPanic(w, fmt.Sprintf("```yaml\n%v```\n", formattedDoc2))
files = "sample.yml another.yml"
command = "eval-all"
command = "eval-all "
}
writeOrPanic(w, "then\n")
if s.expression != "" {
writeOrPanic(w, fmt.Sprintf("```bash\n%vyq %v '%v' %v\n```\n", envCommand, command, s.expression, files))
writeOrPanic(w, fmt.Sprintf("```bash\n%vyq %v'%v' %v\n```\n", envCommand, command, s.expression, files))
} else {
writeOrPanic(w, fmt.Sprintf("```bash\n%vyq %v %v\n```\n", envCommand, command, files))
writeOrPanic(w, fmt.Sprintf("```bash\n%vyq %v%v\n```\n", envCommand, command, files))
}
} else {
writeOrPanic(w, "Running\n")
writeOrPanic(w, fmt.Sprintf("```bash\n%vyq %v --null-input '%v'\n```\n", envCommand, command, s.expression))
writeOrPanic(w, fmt.Sprintf("```bash\n%vyq %v--null-input '%v'\n```\n", envCommand, command, s.expression))
}
return formattedDoc, formattedDoc2
}

View File

@ -369,7 +369,7 @@ func documentXmlDecodeScenario(t *testing.T, w *bufio.Writer, s formatScenario)
if expression == "" {
expression = "."
}
writeOrPanic(w, fmt.Sprintf("```bash\nyq e -p=xml '%v' sample.xml\n```\n", expression))
writeOrPanic(w, fmt.Sprintf("```bash\nyq -p=xml '%v' sample.xml\n```\n", expression))
writeOrPanic(w, "will output\n")
var output bytes.Buffer
@ -398,7 +398,7 @@ func documentXmlEncodeScenario(w *bufio.Writer, s formatScenario) {
writeOrPanic(w, fmt.Sprintf("```yaml\n%v\n```\n", s.input))
writeOrPanic(w, "then\n")
writeOrPanic(w, "```bash\nyq e -o=xml '.' sample.yml\n```\n")
writeOrPanic(w, "```bash\nyq -o=xml '.' sample.yml\n```\n")
writeOrPanic(w, "will output\n")
writeOrPanic(w, fmt.Sprintf("```xml\n%v```\n\n", processXmlScenario(s)))
@ -416,7 +416,7 @@ func documentXmlRoundTripScenario(w *bufio.Writer, s formatScenario) {
writeOrPanic(w, fmt.Sprintf("```xml\n%v\n```\n", s.input))
writeOrPanic(w, "then\n")
writeOrPanic(w, "```bash\nyq e -p=xml -o=xml '.' sample.xml\n```\n")
writeOrPanic(w, "```bash\nyq -p=xml -o=xml '.' sample.xml\n```\n")
writeOrPanic(w, "will output\n")
writeOrPanic(w, fmt.Sprintf("```xml\n%v```\n\n", processXmlScenario(s)))

View File

@ -1,6 +1,6 @@
4.18.1:
- `eval` is now the _default_ command, you can leave it out
- `-` no longer needs to be specified as STDIN, unless you are also working with multiple files.
- `eval` is now the _default_ command, you can leave it out #113
- `-` no longer needs to be specified as STDIN, unless you are also working with multiple files. #113
- Adding to empty maps / arrays now uses idiomatic yaml styling by default
- Fixed seg fault on bad input #1086
- New `envsubst` operator! (thanks @sciyoshi)