yq icon indicating copy to clipboard operation
yq copied to clipboard

Multiply (merge) support appending arrays without creating duplicates

Open mikkel3000 opened this issue 2 years ago • 2 comments

Request When merging yaml files containing arrays using the "+" flag, it will create duplicates if some of the arrays are equal in the two documents. I would like an additional flag("a" in the example) which appends lists without creating duplicates.

Example If we have data1.yml like:

equalList:
  - a
  - b
changedList:
  - a
  - b

And data2.yml like:

equalList:
  - a
  - b
changedList:
  - c

And we run a command:

yq eval-all '. as $item ireduce ({}; . *+ $item)' data1.yml data2.yml

the current output is:

equalList:
  - a
  - b
  - a
  - b
changedList:
  - a
  - b
  - c

With a new flag ("a" in this example) the output should be:

yq eval-all '. as $item ireduce ({}; . *a $item)' data1.yml data2.yml
equalList:
  - a
  - b
changedList:
  - a
  - b
  - c

mikkel3000 avatar Jun 19 '23 09:06 mikkel3000

we do this here: https://github.com/openstack/kolla-ansible/tree/stable/yoga/ansible/action_plugins

is this of any use?

scrungus avatar Jul 18 '23 12:07 scrungus