1
0
mirror of https://github.com/taigrr/yq synced 2025-01-18 04:53:17 -08:00

Added merge if empty

This commit is contained in:
Mike Farah
2021-01-13 16:54:28 +11:00
parent 0bf3d781f6
commit 85398727ad
11 changed files with 125 additions and 60 deletions

View File

@@ -111,6 +111,26 @@ b:
- 5
```
## Merge, only existing fields
Given a sample.yml file of:
```yaml
a:
thing: one
cat: frog
b:
missing: two
thing: two
```
then
```bash
yq eval '.a *? .b' sample.yml
```
will output
```yaml
thing: two
cat: frog
```
## Merge, appending arrays
Given a sample.yml file of:
```yaml
@@ -143,6 +163,33 @@ array:
value: banana
```
## Merge, only existing fields, appending arrays
Given a sample.yml file of:
```yaml
a:
thing:
- 1
- 2
b:
thing:
- 3
- 4
another:
- 1
```
then
```bash
yq eval '.a *?+ .b' sample.yml
```
will output
```yaml
thing:
- 1
- 2
- 3
- 4
```
## Merge to prefix an element
Given a sample.yml file of:
```yaml