Merge
Yaml files can be merged using the 'merge' command. Each additional file merged with the first file will set values for any key not existing already or where the key has no value.
To Stdout¶
Given a data1.yaml file of:
and data2.yaml file of:
then
will output:
Updating files in-place¶
Given a data1.yaml file of:
and data2.yaml file of:
then
will update the data1.yaml file so that the value of 'c' is 'test: 1'.
Overwrite values¶
Given a data1.yaml file of:
and data2.yaml file of:
then
will output:
Overwrite values with arrays¶
Given a data1.yaml file of:
and data3.yaml file of:
then
will output:
Notice that 'b' does not result in the merging of the values within an array.
Append values with arrays¶
Given a data1.yaml file of:
and data3.yaml file of:
then
will output:
Note that the 'b' array has concatenated the values from the second data file. Also note that other map keys are not overridden (field a).
Append cannot be used with overwrite, if both flags are given then append is ignored.
Multiple Documents - merge into single document¶
Currently yq only has multi-document support for the first document being merged into. The remaining yaml files will have their first document selected.
Given a data1.yaml file of:
and data3.yaml file of:
then
will output:
Multiple Documents - merge into all documents¶
Currently yq only has multi-document support for the first document being merged into. The remaining yaml files will have their first document selected.
Given a data1.yaml file of:
and data3.yaml file of:
then
will output:
Last updated