Skip to content

Use yq to merge duplicate map keys in a single file #2120

Closed Answered by maartenSXM
maartenSXM asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @mikefarah, Your reply helped me reduce the number of temporary files created down to one by doing this:

awk '/^[^[:space:]]/{print "---"};{print $0}' file3.yaml > file3.yaml.tmp && mv file3.yaml.tmp file3.yaml
yq --inplace eval-all '. as $item ireduce ({}; . *+ $item)' file3.yaml

This solution will scale to very large numbers of map keys since it does not generate one file per map key. Thank you.

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by maartenSXM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants