This commit is contained in:
Mike Farah 2024-12-07 17:35:26 +11:00
parent 57e4639631
commit 19118c5552

View File

@ -37,6 +37,25 @@ fruit: banana
name: sam name: sam
``` ```
## Get parent attribute
Given a sample.yml file of:
```yaml
a:
fruit: apple
name: bob
b:
fruit: banana
name: sam
```
then
```bash
yq '.. | select(. == "banana") | parent.name' sample.yml
```
will output
```yaml
sam
```
## N-th parent ## N-th parent
You can optionally supply the number of levels to go up for the parent, the default being 1. You can optionally supply the number of levels to go up for the parent, the default being 1.