mirror of
https://github.com/taigrr/yq
synced 2025-01-18 04:53:17 -08:00
Added pipe and length docs, fix pipe precedence
This commit is contained in:
@@ -8,7 +8,7 @@ This will do a similar thing to the plain form, however, the RHS expression is r
|
||||
## Create yaml file
|
||||
Running
|
||||
```bash
|
||||
yq eval --null-input '(.a.b = "cat") | (.x = "frog")'
|
||||
yq eval --null-input '.a.b = "cat" | .x = "frog"'
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
@@ -112,7 +112,7 @@ a:
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq eval '.a.[] | select(. == "apple") |= "frog"' sample.yml
|
||||
yq eval '(.a.[] | select(. == "apple")) = "frog"' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
@@ -130,7 +130,7 @@ Given a sample.yml file of:
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq eval '.[] | select(. == "*andy") |= "bogs"' sample.yml
|
||||
yq eval '(.[] | select(. == "*andy")) = "bogs"' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
|
||||
54
pkg/yqlib/doc/Length.md
Normal file
54
pkg/yqlib/doc/Length.md
Normal file
@@ -0,0 +1,54 @@
|
||||
Returns the lengths of the nodes. Length is defined according to the type of the node.
|
||||
|
||||
## String length
|
||||
returns length of string
|
||||
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
a: cat
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq eval '.a | length' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
3
|
||||
```
|
||||
|
||||
## Map length
|
||||
returns number of entries
|
||||
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
a: cat
|
||||
c: dog
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq eval 'length' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
2
|
||||
```
|
||||
|
||||
## Array length
|
||||
returns number of elements
|
||||
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
- 2
|
||||
- 4
|
||||
- 6
|
||||
- 8
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq eval 'length' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
4
|
||||
```
|
||||
|
||||
35
pkg/yqlib/doc/Pipe.md
Normal file
35
pkg/yqlib/doc/Pipe.md
Normal file
@@ -0,0 +1,35 @@
|
||||
Pipe the results of an expression into another. Like the bash operator.
|
||||
|
||||
## Simple Pipe
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
a:
|
||||
b: cat
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq eval '.a | .b' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
cat
|
||||
```
|
||||
|
||||
## Multiple updates
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
a: cow
|
||||
b: sheep
|
||||
c: same
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq eval '.a = "cat" | .b = "dog"' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
a: cat
|
||||
b: dog
|
||||
c: same
|
||||
```
|
||||
|
||||
1
pkg/yqlib/doc/headers/Length.md
Normal file
1
pkg/yqlib/doc/headers/Length.md
Normal file
@@ -0,0 +1 @@
|
||||
Returns the lengths of the nodes. Length is defined according to the type of the node.
|
||||
1
pkg/yqlib/doc/headers/Pipe.md
Normal file
1
pkg/yqlib/doc/headers/Pipe.md
Normal file
@@ -0,0 +1 @@
|
||||
Pipe the results of an expression into another. Like the bash operator.
|
||||
Reference in New Issue
Block a user