2021-10-30 03:14:39 +00:00
|
|
|
# Pipe
|
|
|
|
|
|
|
|
Pipe the results of an expression into another. Like the bash operator.
|
|
|
|
|
2022-02-06 03:41:27 +00:00
|
|
|
{% hint style="warning" %}
|
|
|
|
Note that versions prior to 4.18 require the 'eval/e' command to be specified. 
|
|
|
|
|
|
|
|
`yq e <exp> <file>`
|
|
|
|
{% endhint %}
|
|
|
|
|
2021-10-30 03:14:39 +00:00
|
|
|
## Simple Pipe
|
|
|
|
Given a sample.yml file of:
|
|
|
|
```yaml
|
|
|
|
a:
|
|
|
|
b: cat
|
|
|
|
```
|
|
|
|
then
|
|
|
|
```bash
|
2022-01-28 01:45:43 +00:00
|
|
|
yq '.a | .b' sample.yml
|
2021-10-30 03:14:39 +00:00
|
|
|
```
|
|
|
|
will output
|
|
|
|
```yaml
|
|
|
|
cat
|
|
|
|
```
|
|
|
|
|
|
|
|
## Multiple updates
|
|
|
|
Given a sample.yml file of:
|
|
|
|
```yaml
|
|
|
|
a: cow
|
|
|
|
b: sheep
|
|
|
|
c: same
|
|
|
|
```
|
|
|
|
then
|
|
|
|
```bash
|
2022-01-28 01:45:43 +00:00
|
|
|
yq '.a = "cat" | .b = "dog"' sample.yml
|
2021-10-30 03:14:39 +00:00
|
|
|
```
|
|
|
|
will output
|
|
|
|
```yaml
|
|
|
|
a: cat
|
|
|
|
b: dog
|
|
|
|
c: same
|
|
|
|
```
|
2021-11-03 04:00:28 +00:00
|
|
|
|