diff --git a/operators/parent.md b/operators/parent.md index 9bdc6822..94fd3fa4 100644 --- a/operators/parent.md +++ b/operators/parent.md @@ -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.