Can traverse straight from parent operator (parent.blah)

This commit is contained in:
Mike Farah
2024-09-06 12:46:23 +10:00
parent dff0122481
commit 1846006082
3 changed files with 29 additions and 2 deletions
+19
View File
@@ -37,6 +37,25 @@ fruit: banana
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
You can optionally supply the number of levels to go up for the parent, the default being 1.