2021-11-03 04:00:58 +00:00
|
|
|
# Split into Documents
|
|
|
|
|
|
|
|
This operator splits all matches into separate documents
|
|
|
|
|
2022-02-06 03:39:46 +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-11-03 04:00:58 +00:00
|
|
|
## Split empty
|
|
|
|
Running
|
|
|
|
```bash
|
2022-02-10 22:05:17 +00:00
|
|
|
yq --null-input 'split_doc'
|
2021-11-03 04:00:58 +00:00
|
|
|
```
|
|
|
|
will output
|
|
|
|
```yaml
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
## Split array
|
|
|
|
Given a sample.yml file of:
|
|
|
|
```yaml
|
|
|
|
- a: cat
|
|
|
|
- b: dog
|
|
|
|
```
|
|
|
|
then
|
|
|
|
```bash
|
2022-02-10 22:05:17 +00:00
|
|
|
yq '.[] | split_doc' sample.yml
|
2021-11-03 04:00:58 +00:00
|
|
|
```
|
|
|
|
will output
|
|
|
|
```yaml
|
|
|
|
a: cat
|
|
|
|
---
|
|
|
|
b: dog
|
|
|
|
```
|
|
|
|
|