From 19118c5552e3a7c8aecca04a71aa5d609256589a Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Sat, 7 Dec 2024 17:35:26 +1100 Subject: [PATCH] v4.44.5 --- operators/parent.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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.