This commit is contained in:
Mike Farah
2022-11-11 14:58:39 +11:00
parent db8a7617ce
commit 245a3dbe34
8 changed files with 95 additions and 8 deletions
+23
View File
@@ -80,3 +80,26 @@ will output
- frog
```
## Inserting into the middle of an array
using an expression to find the index
Given a sample.yml file of:
```yaml
- cat
- dog
- frog
- cow
```
then
```bash
yq '(.[] | select(. == "dog") | key + 1) as $pos | .[0:($pos)] + ["rabbit"] + .[$pos:]' sample.yml
```
will output
```yaml
- cat
- dog
- rabbit
- frog
- cow
```