mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-10 16:55:40 +00:00
document how to add anchors/alias to array
This commit is contained in:
parent
892308bf54
commit
0e6323f88a
@ -331,3 +331,48 @@ thingTwo:
|
||||
!!merge <<: *item_value
|
||||
```
|
||||
|
||||
## Add Anchor to array
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
anchorList:
|
||||
- &one first
|
||||
- &two second
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq '.anchorList += "third" | (.anchorList[-1] anchor="three")' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
anchorList:
|
||||
- &one first
|
||||
- &two second
|
||||
- &three third
|
||||
```
|
||||
|
||||
## Add Alias to array
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
anchorList:
|
||||
- &one first
|
||||
- &two second
|
||||
- &three third
|
||||
anchorRefList:
|
||||
- *one
|
||||
- *two
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq '.anchorRefList += "TMP" | (.anchorRefList[-1] anchor="three")' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
anchorList:
|
||||
- &one first
|
||||
- &two second
|
||||
- &three third
|
||||
anchorRefList:
|
||||
- *one
|
||||
- *two
|
||||
- *three
|
||||
```
|
||||
|
||||
Loading…
Reference in New Issue
Block a user