diff --git a/README.md b/README.md index 1b8aeb1..465f2c4 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,8 @@ docker run -it -v ${PWD}:/workdir mikefarah/yq sh - Convert from yaml to json - Pipe data in by using '-' - Merge multiple yaml files where each additional file sets values for missing or null value keys. -- Merge multiple yaml files with overwrite to support overriding previous values. +- Merge multiple yaml files and override previous values. +- Merge multiple yaml files and append array values. - Supports multiple documents in a single yaml file ## [Usage](http://mikefarah.github.io/yq/) @@ -64,7 +65,7 @@ Usage: Available Commands: delete yq d [--inplace/-i] [--doc/-d index] sample.yaml a.b.c help Help about any command - merge yq m [--inplace/-i] [--doc/-d index] [--overwrite/-x] sample.yaml sample2.yaml + merge yq m [--inplace/-i] [--doc/-d index] [--overwrite/-x] [--append/-a] sample.yaml sample2.yaml new yq n [--script/-s script_file] a.b.c newValue read yq r [--doc/-d index] sample.yaml a.b.c write yq w [--inplace/-i] [--script/-s script_file] [--doc/-d index] sample.yaml a.b.c newValue diff --git a/docs/merge/index.html b/docs/merge/index.html index 41e10c8..cb95e95 100644 --- a/docs/merge/index.html +++ b/docs/merge/index.html @@ -323,6 +323,13 @@ Overwrite values with arrays + + +
and data3.yaml file of:
-b: [2, 3, 4]
+b: [3, 4]
c:
test: 2
other: true
@@ -515,15 +529,44 @@ d: false
will output:
a: simple
-b: [2, 3, 4]
+b: [3, 4]
c:
test: 2
other: true
d: false
-Notice that 'b' does not result in the merging of the values within an array. The underlying library does not
-currently handle merging values within an array.
+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:
+a: simple
+b: [1, 2]
+d: hi
+
+
+and data3.yaml file of:
+a: something
+b: [3, 4]
+c:
+ test: 2
+ other: true
+
+
+then
+yq m -a data1.yaml data3.yaml
+
+
+will output:
+a: simple
+b: [1, 2, 3, 4]
+c:
+ test: 2
+ other: true
+d: hi
+
+
+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:
diff --git a/docs/search/search_index.json b/docs/search/search_index.json
index 04845b5..2e6f037 100644
--- a/docs/search/search_index.json
+++ b/docs/search/search_index.json
@@ -187,7 +187,7 @@
},
{
"location": "/merge/",
- "text": "Yaml files can be merged using the 'merge' command. Each additional file merged with the first file will\nset values for any key not existing already or where the key has no value.\n\n\nyq m ...\n\n\n\n\nTo Stdout\n\u00b6\n\n\nGiven a data1.yaml file of:\n\n\na: simple\nb: [1, 2]\n\n\n\n\nand data2.yaml file of:\n\n\na: other\nc:\n test: 1\n\n\n\n\nthen\n\n\nyq m data1.yaml data2.yaml\n\n\n\n\nwill output:\n\n\na: simple\nb: [1, 2]\nc:\n test: 1\n\n\n\n\nUpdating files in-place\n\u00b6\n\n\nGiven a data1.yaml file of:\n\n\na: simple\nb: [1, 2]\n\n\n\n\nand data2.yaml file of:\n\n\na: other\nc:\n test: 1\n\n\n\n\nthen\n\n\nyq m -i data1.yaml data2.yaml\n\n\n\n\nwill update the data1.yaml file so that the value of 'c' is 'test: 1'.\n\n\nOverwrite values\n\u00b6\n\n\nGiven a data1.yaml file of:\n\n\na: simple\nb: [1, 2]\n\n\n\n\nand data2.yaml file of:\n\n\na: other\nc:\n test: 1\n\n\n\n\nthen\n\n\nyq m -x data1.yaml data2.yaml\n\n\n\n\nwill output:\n\n\na: other\nb: [1, 2]\nc:\n test: 1\n\n\n\n\nOverwrite values with arrays\n\u00b6\n\n\nGiven a data1.yaml file of:\n\n\na: simple\nb: [1, 2]\n\n\n\n\nand data3.yaml file of:\n\n\nb: [2, 3, 4]\nc:\n test: 2\n other: true\nd: false\n\n\n\n\nthen\n\n\nyq m -x data1.yaml data3.yaml\n\n\n\n\nwill output:\n\n\na: simple\nb: [2, 3, 4]\nc:\n test: 2\n other: true\nd: false\n\n\n\n\nNotice that 'b' does not result in the merging of the values within an array. The underlying library does not\ncurrently handle merging values within an array.\n\n\nMultiple Documents - merge into single document\n\u00b6\n\n\nCurrently yq only has multi-document support for the \nfirst\n document being merged into. The remaining yaml files will have their first document selected.\n\n\nGiven a data1.yaml file of:\n\n\nsomething: else\n---\na: simple\nb: cat\n\n\n\n\nand data3.yaml file of:\n\n\nb: dog\n\n\n\n\nthen\n\n\nyq m -x -d1 data1.yaml data3.yaml\n\n\n\n\nwill output:\n\n\nsomething: else\n---\na: simple\nb: dog\n\n\n\n\nMultiple Documents - merge into all documents\n\u00b6\n\n\nCurrently yq only has multi-document support for the \nfirst\n document being merged into. The remaining yaml files will have their first document selected.\n\n\nGiven a data1.yaml file of:\n\n\nsomething: else\n---\na: simple\nb: cat\n\n\n\n\nand data3.yaml file of:\n\n\nb: dog\n\n\n\n\nthen\n\n\nyq m -x -d'*' data1.yaml data3.yaml\n\n\n\n\nwill output:\n\n\nb: dog\nsomething: else\n---\na: simple\nb: dog",
+ "text": "Yaml files can be merged using the 'merge' command. Each additional file merged with the first file will\nset values for any key not existing already or where the key has no value.\n\n\nyq m ...\n\n\n\n\nTo Stdout\n\u00b6\n\n\nGiven a data1.yaml file of:\n\n\na: simple\nb: [1, 2]\n\n\n\n\nand data2.yaml file of:\n\n\na: other\nc:\n test: 1\n\n\n\n\nthen\n\n\nyq m data1.yaml data2.yaml\n\n\n\n\nwill output:\n\n\na: simple\nb: [1, 2]\nc:\n test: 1\n\n\n\n\nUpdating files in-place\n\u00b6\n\n\nGiven a data1.yaml file of:\n\n\na: simple\nb: [1, 2]\n\n\n\n\nand data2.yaml file of:\n\n\na: other\nc:\n test: 1\n\n\n\n\nthen\n\n\nyq m -i data1.yaml data2.yaml\n\n\n\n\nwill update the data1.yaml file so that the value of 'c' is 'test: 1'.\n\n\nOverwrite values\n\u00b6\n\n\nGiven a data1.yaml file of:\n\n\na: simple\nb: [1, 2]\n\n\n\n\nand data2.yaml file of:\n\n\na: other\nc:\n test: 1\n\n\n\n\nthen\n\n\nyq m -x data1.yaml data2.yaml\n\n\n\n\nwill output:\n\n\na: other\nb: [1, 2]\nc:\n test: 1\n\n\n\n\nOverwrite values with arrays\n\u00b6\n\n\nGiven a data1.yaml file of:\n\n\na: simple\nb: [1, 2]\n\n\n\n\nand data3.yaml file of:\n\n\nb: [3, 4]\nc:\n test: 2\n other: true\nd: false\n\n\n\n\nthen\n\n\nyq m -x data1.yaml data3.yaml\n\n\n\n\nwill output:\n\n\na: simple\nb: [3, 4]\nc:\n test: 2\n other: true\nd: false\n\n\n\n\nNotice that 'b' does not result in the merging of the values within an array. \n\n\nAppend values with arrays\n\u00b6\n\n\nGiven a data1.yaml file of:\n\n\na: simple\nb: [1, 2]\nd: hi\n\n\n\n\nand data3.yaml file of:\n\n\na: something\nb: [3, 4]\nc:\n test: 2\n other: true\n\n\n\n\nthen\n\n\nyq m -a data1.yaml data3.yaml\n\n\n\n\nwill output:\n\n\na: simple\nb: [1, 2, 3, 4]\nc:\n test: 2\n other: true\nd: hi\n\n\n\n\nNote that the 'b' array has concatenated the values from the second data file. Also note that other map keys are not overridden (field a).\n\n\nAppend cannot be used with overwrite, if both flags are given then append is ignored.\n\n\nMultiple Documents - merge into single document\n\u00b6\n\n\nCurrently yq only has multi-document support for the \nfirst\n document being merged into. The remaining yaml files will have their first document selected.\n\n\nGiven a data1.yaml file of:\n\n\nsomething: else\n---\na: simple\nb: cat\n\n\n\n\nand data3.yaml file of:\n\n\nb: dog\n\n\n\n\nthen\n\n\nyq m -x -d1 data1.yaml data3.yaml\n\n\n\n\nwill output:\n\n\nsomething: else\n---\na: simple\nb: dog\n\n\n\n\nMultiple Documents - merge into all documents\n\u00b6\n\n\nCurrently yq only has multi-document support for the \nfirst\n document being merged into. The remaining yaml files will have their first document selected.\n\n\nGiven a data1.yaml file of:\n\n\nsomething: else\n---\na: simple\nb: cat\n\n\n\n\nand data3.yaml file of:\n\n\nb: dog\n\n\n\n\nthen\n\n\nyq m -x -d'*' data1.yaml data3.yaml\n\n\n\n\nwill output:\n\n\nb: dog\nsomething: else\n---\na: simple\nb: dog",
"title": "Merge"
},
{
@@ -207,9 +207,14 @@
},
{
"location": "/merge/#overwrite-values-with-arrays",
- "text": "Given a data1.yaml file of: a: simple\nb: [1, 2] and data3.yaml file of: b: [2, 3, 4]\nc:\n test: 2\n other: true\nd: false then yq m -x data1.yaml data3.yaml will output: a: simple\nb: [2, 3, 4]\nc:\n test: 2\n other: true\nd: false Notice that 'b' does not result in the merging of the values within an array. The underlying library does not\ncurrently handle merging values within an array.",
+ "text": "Given a data1.yaml file of: a: simple\nb: [1, 2] and data3.yaml file of: b: [3, 4]\nc:\n test: 2\n other: true\nd: false then yq m -x data1.yaml data3.yaml will output: a: simple\nb: [3, 4]\nc:\n test: 2\n other: true\nd: false Notice that 'b' does not result in the merging of the values within an array.",
"title": "Overwrite values with arrays"
},
+ {
+ "location": "/merge/#append-values-with-arrays",
+ "text": "Given a data1.yaml file of: a: simple\nb: [1, 2]\nd: hi and data3.yaml file of: a: something\nb: [3, 4]\nc:\n test: 2\n other: true then yq m -a data1.yaml data3.yaml will output: a: simple\nb: [1, 2, 3, 4]\nc:\n test: 2\n other: true\nd: hi 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.",
+ "title": "Append values with arrays"
+ },
{
"location": "/merge/#multiple-documents-merge-into-single-document",
"text": "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: something: else\n---\na: simple\nb: cat and data3.yaml file of: b: dog then yq m -x -d1 data1.yaml data3.yaml will output: something: else\n---\na: simple\nb: dog",
diff --git a/docs/sitemap.xml b/docs/sitemap.xml
index 3b282c1..5199c8e 100644
--- a/docs/sitemap.xml
+++ b/docs/sitemap.xml
@@ -4,7 +4,7 @@
/
- 2018-06-20
+ 2018-07-07
daily
@@ -12,7 +12,7 @@
/read/
- 2018-06-20
+ 2018-07-07
daily
@@ -20,7 +20,7 @@
/write/
- 2018-06-20
+ 2018-07-07
daily
@@ -28,7 +28,7 @@
/delete/
- 2018-06-20
+ 2018-07-07
daily
@@ -36,7 +36,7 @@
/create/
- 2018-06-20
+ 2018-07-07
daily
@@ -44,7 +44,7 @@
/convert/
- 2018-06-20
+ 2018-07-07
daily
@@ -52,7 +52,7 @@
/merge/
- 2018-06-20
+ 2018-07-07
daily
diff --git a/mkdocs/merge.md b/mkdocs/merge.md
index b2c0c5a..41d7740 100644
--- a/mkdocs/merge.md
+++ b/mkdocs/merge.md
@@ -80,7 +80,7 @@ b: [1, 2]
```
and data3.yaml file of:
```yaml
-b: [2, 3, 4]
+b: [3, 4]
c:
test: 2
other: true
@@ -93,15 +93,47 @@ yq m -x data1.yaml data3.yaml
will output:
```yaml
a: simple
-b: [2, 3, 4]
+b: [3, 4]
c:
test: 2
other: true
d: false
```
-Notice that 'b' does not result in the merging of the values within an array. The underlying library does not
-currently handle merging values within an array.
+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:
+```yaml
+a: simple
+b: [1, 2]
+d: hi
+```
+and data3.yaml file of:
+```yaml
+a: something
+b: [3, 4]
+c:
+ test: 2
+ other: true
+```
+then
+```bash
+yq m -a data1.yaml data3.yaml
+```
+will output:
+```yaml
+a: simple
+b: [1, 2, 3, 4]
+c:
+ test: 2
+ other: true
+d: hi
+```
+
+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.