yq/pkg/yqlib/doc/headers/Multiply (Merge).md

21 lines
901 B
Markdown
Raw Normal View History

Like the multiple operator in jq, depending on the operands, this multiply operator will do different things. Currently numbers, arrays and objects are supported.
2020-11-17 22:44:16 +00:00
## Objects and arrays - merging
Objects are merged deeply matching on matching keys. By default, array values override and are not deeply merged.
2020-11-22 02:16:54 +00:00
Note that when merging objects, this operator returns the merged object (not the parent). This will be clearer in the examples below.
### Merge Flags
You can control how objects are merged by using one or more of the following flags. Multiple flags can be used together, e.g. `.a *+? .b`. See examples below
2021-01-14 09:28:57 +00:00
- `+` to append arrays
- `?` to only merge existing fields
- `d` to deeply merge arrays
### Merging files
2021-01-14 09:28:57 +00:00
Note the use of `eval-all` to ensure all documents are loaded into memory.
2020-11-22 02:16:54 +00:00
```bash
yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' file1.yaml file2.yaml
```