mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Updating docs
This commit is contained in:
parent
6f27cb93d1
commit
a6fc7aa881
2
.github/ISSUE_TEMPLATE/feature_request.md
vendored
2
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@ -26,7 +26,7 @@ country: Australia
|
|||||||
And we run a command:
|
And we run a command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
yq eval 'predictWeatherOf(.country)'
|
yq 'predictWeatherOf(.country)'
|
||||||
```
|
```
|
||||||
|
|
||||||
it could output
|
it could output
|
||||||
|
41
README.md
41
README.md
@ -11,32 +11,35 @@ yq is written in go - so you can download a dependency free binary for your plat
|
|||||||
|
|
||||||
Read a value:
|
Read a value:
|
||||||
```bash
|
```bash
|
||||||
yq e '.a.b[0].c' file.yaml
|
yq '.a.b[0].c' file.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
Pipe from STDIN:
|
Pipe from STDIN:
|
||||||
```bash
|
```bash
|
||||||
cat file.yaml | yq e '.a.b[0].c' -
|
cat file.yaml | yq '.a.b[0].c'
|
||||||
```
|
```
|
||||||
|
|
||||||
Update a yaml file, inplace
|
Update a yaml file, inplace
|
||||||
```bash
|
```bash
|
||||||
yq e -i '.a.b[0].c = "cool"' file.yaml
|
yq -i '.a.b[0].c = "cool"' file.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
Update using environment variables
|
Update using environment variables
|
||||||
```bash
|
```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
|
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
|
yq ea '. as $item ireduce ({}; . * $item )' path/to/*.yml
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
Multiple updates to a yaml file
|
Multiple updates to a yaml file
|
||||||
```bash
|
```bash
|
||||||
yq e -i '
|
yq -i '
|
||||||
.a.b[0].c = "cool" |
|
.a.b[0].c = "cool" |
|
||||||
.x.y.z = "foobar" |
|
.x.y.z = "foobar" |
|
||||||
.person.name = strenv(NAME)
|
.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:
|
`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):
|
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:
|
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
|
sudo mv /etc/myfile.tmp /etc/myfile
|
||||||
rm /etc/myfile.tmp
|
rm /etc/myfile.tmp
|
||||||
```
|
```
|
||||||
@ -101,14 +104,14 @@ rm /etc/myfile.tmp
|
|||||||
#### Oneshot use:
|
#### Oneshot use:
|
||||||
|
|
||||||
```bash
|
```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,
|
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`.
|
namely `--security-opt=no-new-privileges --cap-drop all --network none`.
|
||||||
|
|
||||||
```bash
|
```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:
|
#### 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:
|
You'll need to pass the `-i\--interactive` flag to docker:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cat myfile.yml | docker run -i --rm mikefarah/yq e . -
|
cat myfile.yml | docker run -i --rm mikefarah/yq '.this.thing'
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```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:
|
#### Run commands interactively:
|
||||||
@ -176,7 +179,7 @@ USER yq
|
|||||||
- name: Set foobar to cool
|
- name: Set foobar to cool
|
||||||
uses: mikefarah/yq@master
|
uses: mikefarah/yq@master
|
||||||
with:
|
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.
|
See https://mikefarah.gitbook.io/yq/usage/github-action for more.
|
||||||
@ -270,9 +273,17 @@ Usage:
|
|||||||
yq [flags]
|
yq [flags]
|
||||||
yq [command]
|
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:
|
Available Commands:
|
||||||
completion Generate the autocompletion script for the specified shell
|
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
|
eval-all Loads _all_ yaml documents of _all_ yaml files and runs expression once
|
||||||
help Help about any command
|
help Help about any command
|
||||||
shell-completion Generate completion script
|
shell-completion Generate completion script
|
||||||
|
@ -5,8 +5,8 @@ setUp() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
testBasicEvalRoundTrip() {
|
testBasicEvalRoundTrip() {
|
||||||
./yq e -n ".a = 123" > test.yml
|
./yq -n ".a = 123" > test.yml
|
||||||
X=$(./yq e '.a' test.yml)
|
X=$(./yq '.a' test.yml)
|
||||||
assertEquals 123 "$X"
|
assertEquals 123 "$X"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,8 +16,11 @@ func New() *cobra.Command {
|
|||||||
See https://mikefarah.gitbook.io/yq/ for detailed documentation and examples.`,
|
See https://mikefarah.gitbook.io/yq/ for detailed documentation and examples.`,
|
||||||
Example: `
|
Example: `
|
||||||
# yq defaults to 'eval' command if no command is specified. See "yq eval --help" for more 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"
|
|
||||||
|
|
||||||
|
# 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
|
yq -i '.stuff = "foo"' myfile.yml # update myfile.yml inplace
|
||||||
`,
|
`,
|
||||||
|
|
||||||
|
@ -20,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
|
||||||
@ -44,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
|
||||||
@ -63,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
|
||||||
@ -79,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
|
||||||
@ -96,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
|
||||||
@ -117,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
|
||||||
@ -143,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
|
||||||
@ -171,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
|
||||||
@ -195,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
|
||||||
@ -213,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
|
||||||
@ -231,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
|
||||||
@ -247,7 +247,7 @@ b: 5
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.[] += 1' sample.yml
|
yq '.[] += 1' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -260,7 +260,7 @@ 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
|
||||||
@ -285,7 +285,7 @@ b:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a += .b' sample.yml
|
yq '.a += .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -312,7 +312,7 @@ b: !goat _meow
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a += .b' sample.yml
|
yq '.a += .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -330,7 +330,7 @@ b: !goat 2.3
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a += .b' sample.yml
|
yq '.a += .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -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
|
||||||
|
@ -13,14 +13,14 @@ To replace environment variables across all values in a document, `envsubst` can
|
|||||||
as follows:
|
as follows:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
yq eval '(.. | select(tag == "!!str")) |= envsubst' file.yaml
|
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
|
||||||
@ -30,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
|
||||||
@ -40,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
|
||||||
@ -50,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
|
||||||
@ -60,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
|
||||||
@ -70,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
|
||||||
@ -85,7 +85,7 @@ 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
|
||||||
@ -95,7 +95,7 @@ meow
|
|||||||
## Replace strings with envsubst
|
## Replace strings with envsubst
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
myenv="cat" yq eval --null-input '"the ${myenv} meows" | envsubst'
|
myenv="cat" yq --null-input '"the ${myenv} meows" | envsubst'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -105,7 +105,7 @@ the cat meows
|
|||||||
## Replace strings with envsubst, missing variables
|
## Replace strings with envsubst, missing variables
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
myenv="cat" yq eval --null-input '"the ${myenvnonexisting} meows" | envsubst'
|
myenv="cat" yq --null-input '"the ${myenvnonexisting} meows" | envsubst'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -115,7 +115,7 @@ the meows
|
|||||||
## Replace strings with envsubst, missing variables with defaults
|
## Replace strings with envsubst, missing variables with defaults
|
||||||
Running
|
Running
|
||||||
```bash
|
```bash
|
||||||
myenv="cat" yq eval --null-input '"the ${myenvnonexisting-dog} meows" | envsubst'
|
myenv="cat" yq --null-input '"the ${myenvnonexisting-dog} meows" | envsubst'
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -129,7 +129,7 @@ v: ${myenv}
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
myenv="cat meow" yq eval '.v |= envsubst' sample.yml
|
myenv="cat meow" yq '.v |= envsubst' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -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
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
yq [eval/eval-all] [expression] files..
|
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
|
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:
|
## Read a value:
|
||||||
```bash
|
```bash
|
||||||
yq e '.a.b[0].c' file.yaml
|
yq '.a.b[0].c' file.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
## Pipe from STDIN:
|
## Pipe from STDIN:
|
||||||
```bash
|
```bash
|
||||||
cat file.yaml | yq e '.a.b[0].c' -
|
cat file.yaml | yq '.a.b[0].c'
|
||||||
```
|
```
|
||||||
|
|
||||||
## Update a yaml file, inplace
|
## Update a yaml file, inplace
|
||||||
```bash
|
```bash
|
||||||
yq e -i '.a.b[0].c = "cool"' file.yaml
|
yq -i '.a.b[0].c = "cool"' file.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
## Update using environment variables
|
## Update using environment variables
|
||||||
```bash
|
```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
|
## Merge multiple files
|
||||||
```
|
```
|
||||||
yq ea '. as $item ireduce ({}; . * $item )' path/to/*.yml
|
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
|
## Multiple updates to a yaml file
|
||||||
```bash
|
```bash
|
||||||
yq e -i '
|
yq -i '
|
||||||
.a.b[0].c = "cool" |
|
.a.b[0].c = "cool" |
|
||||||
.x.y.z = "foobar" |
|
.x.y.z = "foobar" |
|
||||||
.person.name = strenv(NAME)
|
.person.name = strenv(NAME)
|
||||||
|
@ -13,6 +13,6 @@ To replace environment variables across all values in a document, `envsubst` can
|
|||||||
as follows:
|
as follows:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
yq eval '(.. | select(tag == "!!str")) |= envsubst' file.yaml
|
yq '(.. | select(tag == "!!str")) |= envsubst' file.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,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:
|
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
|
||||||
```
|
```
|
@ -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:
|
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.
|
||||||
|
@ -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,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)
|
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
|
||||||
```
|
```
|
||||||
|
@ -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
|
||||||
|
@ -30,7 +30,7 @@ b: 4
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a *= .b' sample.yml
|
yq '.a *= .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -51,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
|
||||||
@ -74,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
|
||||||
@ -98,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
|
||||||
@ -121,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
|
||||||
@ -147,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
|
||||||
@ -167,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
|
||||||
@ -194,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
|
||||||
@ -224,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
|
||||||
@ -251,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
|
||||||
@ -331,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
|
||||||
@ -352,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
|
||||||
@ -372,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
|
||||||
@ -404,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
|
||||||
@ -426,7 +426,7 @@ b: !goat 3
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a = .a * .b' sample.yml
|
yq '.a = .a * .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
@ -446,7 +446,7 @@ b: !goat
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a = .a * .b' sample.yml
|
yq '.a = .a * .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -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
|
||||||
@ -121,7 +121,7 @@ b: !goat 1
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.a -= .b' sample.yml
|
yq '.a -= .b' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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, fmt.Sprintf("```json\n%v\n```\n", s.input))
|
||||||
|
|
||||||
writeOrPanic(w, "then\n")
|
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")
|
writeOrPanic(w, "will output\n")
|
||||||
|
|
||||||
var output bytes.Buffer
|
var output bytes.Buffer
|
||||||
@ -208,9 +208,9 @@ func documentJsonEncodeScenario(w *bufio.Writer, s formatScenario) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if s.indent == 2 {
|
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 {
|
} 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")
|
writeOrPanic(w, "will output\n")
|
||||||
|
|
||||||
|
@ -227,7 +227,7 @@ func documentOperatorScenario(t *testing.T, w *bufio.Writer, i interface{}) {
|
|||||||
func documentInput(w *bufio.Writer, s expressionScenario) (string, string) {
|
func documentInput(w *bufio.Writer, s expressionScenario) (string, string) {
|
||||||
formattedDoc := ""
|
formattedDoc := ""
|
||||||
formattedDoc2 := ""
|
formattedDoc2 := ""
|
||||||
command := "eval"
|
command := ""
|
||||||
|
|
||||||
envCommand := ""
|
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, "And another sample another.yml file of:\n")
|
||||||
writeOrPanic(w, fmt.Sprintf("```yaml\n%v```\n", formattedDoc2))
|
writeOrPanic(w, fmt.Sprintf("```yaml\n%v```\n", formattedDoc2))
|
||||||
files = "sample.yml another.yml"
|
files = "sample.yml another.yml"
|
||||||
command = "eval-all"
|
command = "eval-all "
|
||||||
}
|
}
|
||||||
|
|
||||||
writeOrPanic(w, "then\n")
|
writeOrPanic(w, "then\n")
|
||||||
|
|
||||||
if s.expression != "" {
|
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 {
|
} 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 {
|
} else {
|
||||||
writeOrPanic(w, "Running\n")
|
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
|
return formattedDoc, formattedDoc2
|
||||||
}
|
}
|
||||||
|
@ -369,7 +369,7 @@ func documentXmlDecodeScenario(t *testing.T, w *bufio.Writer, s formatScenario)
|
|||||||
if expression == "" {
|
if expression == "" {
|
||||||
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")
|
writeOrPanic(w, "will output\n")
|
||||||
|
|
||||||
var output bytes.Buffer
|
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, fmt.Sprintf("```yaml\n%v\n```\n", s.input))
|
||||||
|
|
||||||
writeOrPanic(w, "then\n")
|
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, "will output\n")
|
||||||
|
|
||||||
writeOrPanic(w, fmt.Sprintf("```xml\n%v```\n\n", processXmlScenario(s)))
|
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, fmt.Sprintf("```xml\n%v\n```\n", s.input))
|
||||||
|
|
||||||
writeOrPanic(w, "then\n")
|
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, "will output\n")
|
||||||
|
|
||||||
writeOrPanic(w, fmt.Sprintf("```xml\n%v```\n\n", processXmlScenario(s)))
|
writeOrPanic(w, fmt.Sprintf("```xml\n%v```\n\n", processXmlScenario(s)))
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
4.18.1:
|
4.18.1:
|
||||||
- `eval` is now the _default_ command, you can leave it out
|
- `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.
|
- `-` 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
|
- Adding to empty maps / arrays now uses idiomatic yaml styling by default
|
||||||
- Fixed seg fault on bad input #1086
|
- Fixed seg fault on bad input #1086
|
||||||
- New `envsubst` operator! (thanks @sciyoshi)
|
- New `envsubst` operator! (thanks @sciyoshi)
|
||||||
|
Loading…
Reference in New Issue
Block a user