mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 13:48:06 +00:00
merge documentation
This commit is contained in:
parent
52a39bf31e
commit
d8fed62f03
@ -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
|
||||
|
@ -323,6 +323,13 @@
|
||||
Overwrite values with arrays
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#append-values-with-arrays" title="Append values with arrays" class="md-nav__link">
|
||||
Append values with arrays
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
@ -392,6 +399,13 @@
|
||||
Overwrite values with arrays
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#append-values-with-arrays" title="Append values with arrays" class="md-nav__link">
|
||||
Append values with arrays
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
@ -502,7 +516,7 @@ b: [1, 2]
|
||||
</code></pre>
|
||||
|
||||
<p>and data3.yaml file of:</p>
|
||||
<pre><code class="yaml">b: [2, 3, 4]
|
||||
<pre><code class="yaml">b: [3, 4]
|
||||
c:
|
||||
test: 2
|
||||
other: true
|
||||
@ -515,15 +529,44 @@ d: false
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">a: simple
|
||||
b: [2, 3, 4]
|
||||
b: [3, 4]
|
||||
c:
|
||||
test: 2
|
||||
other: true
|
||||
d: false
|
||||
</code></pre>
|
||||
|
||||
<p>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.</p>
|
||||
<p>Notice that 'b' does not result in the merging of the values within an array. </p>
|
||||
<h3 id="append-values-with-arrays">Append values with arrays<a class="headerlink" href="#append-values-with-arrays" title="Permanent link">¶</a></h3>
|
||||
<p>Given a data1.yaml file of:</p>
|
||||
<pre><code class="yaml">a: simple
|
||||
b: [1, 2]
|
||||
d: hi
|
||||
</code></pre>
|
||||
|
||||
<p>and data3.yaml file of:</p>
|
||||
<pre><code class="yaml">a: something
|
||||
b: [3, 4]
|
||||
c:
|
||||
test: 2
|
||||
other: true
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq m -a data1.yaml data3.yaml
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">a: simple
|
||||
b: [1, 2, 3, 4]
|
||||
c:
|
||||
test: 2
|
||||
other: true
|
||||
d: hi
|
||||
</code></pre>
|
||||
|
||||
<p>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).</p>
|
||||
<p>Append cannot be used with overwrite, if both flags are given then append is ignored.</p>
|
||||
<h3 id="multiple-documents-merge-into-single-document">Multiple Documents - merge into single document<a class="headerlink" href="#multiple-documents-merge-into-single-document" title="Permanent link">¶</a></h3>
|
||||
<p>Currently yq only has multi-document support for the <em>first</em> document being merged into. The remaining yaml files will have their first document selected.</p>
|
||||
<p>Given a data1.yaml file of:</p>
|
||||
|
@ -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 <yaml_file> <path>...\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 <yaml_file> <path>...\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",
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
<url>
|
||||
<loc>/</loc>
|
||||
<lastmod>2018-06-20</lastmod>
|
||||
<lastmod>2018-07-07</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
|
||||
<url>
|
||||
<loc>/read/</loc>
|
||||
<lastmod>2018-06-20</lastmod>
|
||||
<lastmod>2018-07-07</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
|
||||
<url>
|
||||
<loc>/write/</loc>
|
||||
<lastmod>2018-06-20</lastmod>
|
||||
<lastmod>2018-07-07</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
|
||||
<url>
|
||||
<loc>/delete/</loc>
|
||||
<lastmod>2018-06-20</lastmod>
|
||||
<lastmod>2018-07-07</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
|
||||
<url>
|
||||
<loc>/create/</loc>
|
||||
<lastmod>2018-06-20</lastmod>
|
||||
<lastmod>2018-07-07</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
@ -44,7 +44,7 @@
|
||||
|
||||
<url>
|
||||
<loc>/convert/</loc>
|
||||
<lastmod>2018-06-20</lastmod>
|
||||
<lastmod>2018-07-07</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
@ -52,7 +52,7 @@
|
||||
|
||||
<url>
|
||||
<loc>/merge/</loc>
|
||||
<lastmod>2018-06-20</lastmod>
|
||||
<lastmod>2018-07-07</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user