Repository navigation
YQ Merge: Overwrite Header Comments Instead of Appending Them #2757
Unanswered
1426217101
asked this question in
Q&A
Replies: 2 comments
|
help me,This is my first time asking for help,Thank you |
0 replies
|
The stacking comes from the merge itself: Grab file1's header first and stamp it back on afterwards: hc=$(yq '. | headComment' file1.yaml)
yq ea '. as $i ireduce({}; . *+ $i)' file1.yaml file2.yaml \
| hc="$hc" yq '. headComment = strenv(hc)'Result: # header comment1
animals:
- cat
- dogThis scales past two files, keeps multi-line headers intact, and if file1 has no header you get no comment line rather than a stray One thing to avoid: 4.53.3. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
When merging two YAML files with the command
yq eval-all '. as $item ireduce({}; . *+ $item)' file1.yaml file2.yaml, the header comments are concatenated instead of overwritten.I hope that during the merge process, the header comments from file1.yaml can overwrite those from file2.yaml, rather than stacking both sets of comments together. I would appreciate any solutions or suggestions.
file1.yaml
file2.yaml
Current Output
Expected Result
All reactions