From fe4a753ca4910a80ab88734c7adb6e35a0af7a3f Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Tue, 29 Mar 2022 13:35:30 +1100 Subject: [PATCH] Added tip --- usage/tips-and-tricks.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/usage/tips-and-tricks.md b/usage/tips-and-tricks.md index 23120525..9ec94082 100644 --- a/usage/tips-and-tricks.md +++ b/usage/tips-and-tricks.md @@ -75,6 +75,13 @@ To merge all given yaml files into one, use the `reduce` operator with the `*` ( yq ea '. as $item ireduce ({}; . * $item )' file1.yml file2.yml ... ``` +## Merge - showing the source file and line +To see the original source file and line number of your merged result, you can pre-process the files and add that information in as line comments, then perform the merge. + +```bash +yq ea '(.. lineComment |= filename + ":" + line) | select(fi==0) * select(fi==1)' data1.yaml data2.yaml +``` + ## Merge an array of objects by key See [here](https://mikefarah.gitbook.io/yq/operators/multiply-merge#merge-arrays-of-objects-together-matching-on-a-key) for a working example.