@@ -540,12 +554,36 @@ bob:
cats: bananas
item2:
cats: apples
+ thing:
+ cats: oranges
then
yq r sample.yaml bob.*.cats
+will output
+- bananas
+- apples
+- oranges
+
+
+Prefix Splat
+Given a sample.yaml file of:
+---
+bob:
+ item1:
+ cats: bananas
+ item2:
+ cats: apples
+ thing:
+ cats: oranges
+
+
+then
+yq r sample.yaml bob.item*.cats
+
+
will output
- bananas
- apples
diff --git a/docs/search/search_index.json b/docs/search/search_index.json
index 47b7191a..c679dc79 100644
--- a/docs/search/search_index.json
+++ b/docs/search/search_index.json
@@ -1 +1,5 @@
-{"config":{"lang":["en"],"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"yq yq is a lightweight and portable command-line YAML processor The aim of the project is to be the jq or sed of yaml files. Install On MacOS: brew install yq On Ubuntu and other Linux distros supporting snap packages: snap install yq On Ubuntu 16.04 or higher from Debian package: sudo add-apt-repository ppa:rmescandon/yq sudo apt update sudo apt install yq -y or, Download latest binary or alternatively: go get gopkg.in/mikefarah/yq.v2 View on GitHub","title":"Install"},{"location":"#yq","text":"yq is a lightweight and portable command-line YAML processor The aim of the project is to be the jq or sed of yaml files.","title":"yq"},{"location":"#install","text":"On MacOS: brew install yq On Ubuntu and other Linux distros supporting snap packages: snap install yq On Ubuntu 16.04 or higher from Debian package: sudo add-apt-repository ppa:rmescandon/yq sudo apt update sudo apt install yq -y or, Download latest binary or alternatively: go get gopkg.in/mikefarah/yq.v2 View on GitHub","title":"Install"},{"location":"convert/","text":"Yaml to Json To convert output to json, use the --tojson (or -j) flag. This can only be used with the read command. Given a sample.yaml file of: b: c: 2 then yq r -j sample.yaml b.c will output { b :{ c :2}} Json to Yaml To read in json, just pass in a json file instead of yaml, it will just work :) e.g given a json file { a : Easy! as one two three , b :{ c :2, d :[3,4]}} then yq r sample.json will output a: Easy! as one two three b: c: 2 d: - 3 - 4","title":"Convert"},{"location":"convert/#yaml-to-json","text":"To convert output to json, use the --tojson (or -j) flag. This can only be used with the read command. Given a sample.yaml file of: b: c: 2 then yq r -j sample.yaml b.c will output { b :{ c :2}}","title":"Yaml to Json"},{"location":"convert/#json-to-yaml","text":"To read in json, just pass in a json file instead of yaml, it will just work :) e.g given a json file { a : Easy! as one two three , b :{ c :2, d :[3,4]}} then yq r sample.json will output a: Easy! as one two three b: c: 2 d: - 3 - 4","title":"Json to Yaml"},{"location":"create/","text":"Yaml files can be created using the 'new' command. This works in the same way as the write command, but you don't pass in an existing Yaml file. Currently this does not support creating multiple documents in a single yaml file. yq n path new value Creating a simple yaml file yq n b.c cat will output: b: c: cat Creating using a create script Create scripts follow the same format as the update scripts. Given a script create_instructions.yaml of: b.c: 3 b.e[0].name: Howdy Partner then yq n -s create_instructions.yaml will output: b: c: 3 e: - name: Howdy Partner You can also pipe the instructions in: cat create_instructions.yaml | yq n -s - Keys with dots When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Create"},{"location":"create/#creating-a-simple-yaml-file","text":"yq n b.c cat will output: b: c: cat","title":"Creating a simple yaml file"},{"location":"create/#creating-using-a-create-script","text":"Create scripts follow the same format as the update scripts. Given a script create_instructions.yaml of: b.c: 3 b.e[0].name: Howdy Partner then yq n -s create_instructions.yaml will output: b: c: 3 e: - name: Howdy Partner You can also pipe the instructions in: cat create_instructions.yaml | yq n -s -","title":"Creating using a create script"},{"location":"create/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"create/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Keys (and values) with leading dashes"},{"location":"delete/","text":"yq d yaml_file path_to_delete To Stdout Given a sample.yaml file of: b: c: 2 apples: green then yq d sample.yaml b.c will output: b: apples: green From STDIN cat sample.yaml | yq d - b.c Deleting array elements Given a sample.yaml file of: b: c: - 1 - 2 - 3 then yq d sample.yaml 'b.c[1]' will output: b: c: - 1 - 3 Deleting nodes in-place Given a sample.yaml file of: b: c: 2 apples: green then yq d -i sample.yaml b.c will update the sample.yaml file so that the 'c' node is deleted Multiple Documents - delete from single document Given a sample.yaml file of: something: else field: leaveMe --- b: c: 2 field: deleteMe then yq w -d1 sample.yaml field will output: something: else field: leaveMe --- b: c: 2 Multiple Documents - delete from all documents Given a sample.yaml file of: something: else field: deleteMe --- b: c: 2 field: deleteMeToo then yq w -d'*' sample.yaml field will output: something: else --- b: c: 2 Note that '*' is in quotes to avoid being interpreted by your shell. Keys with dots When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Delete"},{"location":"delete/#to-stdout","text":"Given a sample.yaml file of: b: c: 2 apples: green then yq d sample.yaml b.c will output: b: apples: green","title":"To Stdout"},{"location":"delete/#from-stdin","text":"cat sample.yaml | yq d - b.c","title":"From STDIN"},{"location":"delete/#deleting-array-elements","text":"Given a sample.yaml file of: b: c: - 1 - 2 - 3 then yq d sample.yaml 'b.c[1]' will output: b: c: - 1 - 3","title":"Deleting array elements"},{"location":"delete/#deleting-nodes-in-place","text":"Given a sample.yaml file of: b: c: 2 apples: green then yq d -i sample.yaml b.c will update the sample.yaml file so that the 'c' node is deleted","title":"Deleting nodes in-place"},{"location":"delete/#multiple-documents-delete-from-single-document","text":"Given a sample.yaml file of: something: else field: leaveMe --- b: c: 2 field: deleteMe then yq w -d1 sample.yaml field will output: something: else field: leaveMe --- b: c: 2","title":"Multiple Documents - delete from single document"},{"location":"delete/#multiple-documents-delete-from-all-documents","text":"Given a sample.yaml file of: something: else field: deleteMe --- b: c: 2 field: deleteMeToo then yq w -d'*' sample.yaml field will output: something: else --- b: c: 2 Note that '*' is in quotes to avoid being interpreted by your shell.","title":"Multiple Documents - delete from all documents"},{"location":"delete/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"delete/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Keys (and values) with leading dashes"},{"location":"merge/","text":"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. yq m yaml_file path ... To Stdout Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m data1.yaml data2.yaml will output: a: simple b: [1, 2] c: test: 1 Updating files in-place Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m -i data1.yaml data2.yaml will update the data1.yaml file so that the value of 'c' is 'test: 1'. Overwrite values Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m -x data1.yaml data2.yaml will output: a: other b: [1, 2] c: test: 1 Overwrite values with arrays Given a data1.yaml file of: a: simple b: [1, 2] and data3.yaml file of: b: [3, 4] c: test: 2 other: true d: false then yq m -x data1.yaml data3.yaml will output: a: simple 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. 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: something: else --- a: simple b: cat and data3.yaml file of: b: dog then yq m -x -d1 data1.yaml data3.yaml will output: something: else --- a: simple b: dog 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: something: else --- a: simple b: cat and data3.yaml file of: b: dog then yq m -x -d'*' data1.yaml data3.yaml will output: b: dog something: else --- a: simple b: dog","title":"Merge"},{"location":"merge/#to-stdout","text":"Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m data1.yaml data2.yaml will output: a: simple b: [1, 2] c: test: 1","title":"To Stdout"},{"location":"merge/#updating-files-in-place","text":"Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m -i data1.yaml data2.yaml will update the data1.yaml file so that the value of 'c' is 'test: 1'.","title":"Updating files in-place"},{"location":"merge/#overwrite-values","text":"Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m -x data1.yaml data2.yaml will output: a: other b: [1, 2] c: test: 1","title":"Overwrite values"},{"location":"merge/#overwrite-values-with-arrays","text":"Given a data1.yaml file of: a: simple b: [1, 2] and data3.yaml file of: b: [3, 4] c: test: 2 other: true d: false then yq m -x data1.yaml data3.yaml will output: a: simple 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.","title":"Overwrite values with arrays"},{"location":"merge/#append-values-with-arrays","text":"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.","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 --- a: simple b: cat and data3.yaml file of: b: dog then yq m -x -d1 data1.yaml data3.yaml will output: something: else --- a: simple b: dog","title":"Multiple Documents - merge into single document"},{"location":"merge/#multiple-documents-merge-into-all-documents","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 --- a: simple b: cat and data3.yaml file of: b: dog then yq m -x -d'*' data1.yaml data3.yaml will output: b: dog something: else --- a: simple b: dog","title":"Multiple Documents - merge into all documents"},{"location":"prefix/","text":"Paths can be prefixed using the 'prefix' command. The complete yaml content will be nested inside the new prefix path. yq p yaml_file path To Stdout Given a data1.yaml file of: a: simple b: [1, 2] then yq p data1.yaml c will output: c: a: simple b: [1, 2] Arbitrary depth Given a data1.yaml file of: a: b: [1, 2] then yq p data1.yaml c.d will output: c: d: a: b: [1, 2] Updating files in-place Given a data1.yaml file of: a: simple b: [1, 2] then yq p -i data1.yaml c will update the data1.yaml file so that the path 'c' is prefixed to all other paths. Multiple Documents - prefix a single document Given a data1.yaml file of: something: else --- a: simple b: cat then yq p -d1 data1.yaml c will output: something: else --- c: a: simple b: cat Multiple Documents - prefix all documents Given a data1.yaml file of: something: else --- a: simple b: cat then yq p -d'*' data1.yaml c will output: c: something: else --- c: a: simple b: cat","title":"Prefix"},{"location":"prefix/#to-stdout","text":"Given a data1.yaml file of: a: simple b: [1, 2] then yq p data1.yaml c will output: c: a: simple b: [1, 2]","title":"To Stdout"},{"location":"prefix/#arbitrary-depth","text":"Given a data1.yaml file of: a: b: [1, 2] then yq p data1.yaml c.d will output: c: d: a: b: [1, 2]","title":"Arbitrary depth"},{"location":"prefix/#updating-files-in-place","text":"Given a data1.yaml file of: a: simple b: [1, 2] then yq p -i data1.yaml c will update the data1.yaml file so that the path 'c' is prefixed to all other paths.","title":"Updating files in-place"},{"location":"prefix/#multiple-documents-prefix-a-single-document","text":"Given a data1.yaml file of: something: else --- a: simple b: cat then yq p -d1 data1.yaml c will output: something: else --- c: a: simple b: cat","title":"Multiple Documents - prefix a single document"},{"location":"prefix/#multiple-documents-prefix-all-documents","text":"Given a data1.yaml file of: something: else --- a: simple b: cat then yq p -d'*' data1.yaml c will output: c: something: else --- c: a: simple b: cat","title":"Multiple Documents - prefix all documents"},{"location":"read/","text":"yq r yaml_file|json_file path This command can take a json file as input too, and will output yaml unless specified to export as json (-j) Basic Given a sample.yaml file of: b: c: 2 then yq r sample.yaml b.c will output the value of '2'. From Stdin Given a sample.yaml file of: cat sample.yaml | yq r - b.c will output the value of '2'. Splat Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples then yq r sample.yaml bob.*.cats will output - bananas - apples Multiple Documents - specify a single document Given a sample.yaml file of: something: else --- b: c: 2 then yq r -d1 sample.yaml b.c will output the value of '2'. Multiple Documents - read all documents Reading all documents will return the result as an array. This can be converted to json using the '-j' flag if desired. Given a sample.yaml file of: name: Fred age: 22 --- name: Stella age: 23 --- name: Android age: 232 then yq r -d'*' sample.yaml name will output: - Fred - Stella - Android Arrays You can give an index to access a specific element: e.g.: given a sample file of b: e: - name: fred value: 3 - name: sam value: 4 then yq r sample.yaml 'b.e[1].name' will output 'sam' Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Array Splat e.g.: given a sample file of b: e: - name: fred value: 3 - name: sam value: 4 then yq r sample.yaml 'b.e[*].name' will output: - fred - sam Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys with dots When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Read"},{"location":"read/#basic","text":"Given a sample.yaml file of: b: c: 2 then yq r sample.yaml b.c will output the value of '2'.","title":"Basic"},{"location":"read/#from-stdin","text":"Given a sample.yaml file of: cat sample.yaml | yq r - b.c will output the value of '2'.","title":"From Stdin"},{"location":"read/#splat","text":"Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples then yq r sample.yaml bob.*.cats will output - bananas - apples","title":"Splat"},{"location":"read/#multiple-documents-specify-a-single-document","text":"Given a sample.yaml file of: something: else --- b: c: 2 then yq r -d1 sample.yaml b.c will output the value of '2'.","title":"Multiple Documents - specify a single document"},{"location":"read/#multiple-documents-read-all-documents","text":"Reading all documents will return the result as an array. This can be converted to json using the '-j' flag if desired. Given a sample.yaml file of: name: Fred age: 22 --- name: Stella age: 23 --- name: Android age: 232 then yq r -d'*' sample.yaml name will output: - Fred - Stella - Android","title":"Multiple Documents - read all documents"},{"location":"read/#arrays","text":"You can give an index to access a specific element: e.g.: given a sample file of b: e: - name: fred value: 3 - name: sam value: 4 then yq r sample.yaml 'b.e[1].name' will output 'sam' Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Arrays"},{"location":"read/#array-splat","text":"e.g.: given a sample file of b: e: - name: fred value: 3 - name: sam value: 4 then yq r sample.yaml 'b.e[*].name' will output: - fred - sam Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Array Splat"},{"location":"read/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"read/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Keys (and values) with leading dashes"},{"location":"write/","text":"yq w yaml_file path new value To Stdout Given a sample.yaml file of: b: c: 2 then yq w sample.yaml b.c cat will output: b: c: cat From STDIN cat sample.yaml | yq w - b.c blah Adding new fields Any missing fields in the path will be created on the fly. Given a sample.yaml file of: b: c: 2 then yq w sample.yaml b.d[0] new thing will output: b: c: cat d: - new thing Appending value to an array field Given a sample.yaml file of: b: c: 2 d: - new thing - foo thing then yq w sample.yaml b.d[+] bar thing will output: b: c: cat d: - new thing - foo thing - bar thing Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Multiple Documents - update a single document Given a sample.yaml file of: something: else --- b: c: 2 then yq w -d1 sample.yaml b.c 5 will output: something: else --- b: c: 5 Multiple Documents - update all documents Given a sample.yaml file of: something: else --- b: c: 2 then yq w -d'*' sample.yaml b.c 5 will output: something: else b: c: 5 --- b: c: 5 Note that '*' is in quotes to avoid being interpreted by your shell. Updating files in-place Given a sample.yaml file of: b: c: 2 then yq w -i sample.yaml b.c cat will update the sample.yaml file so that the value of 'c' is cat. Updating multiple values with a script Given a sample.yaml file of: b: c: 2 e: - name: Billy Bob and a script update_instructions.yaml of: b.c: 3 b.e[0].name: Howdy Partner then yq w -s update_instructions.yaml sample.yaml will output: b: c: 3 e: - name: Howdy Partner And, of course, you can pipe the instructions in using '-': cat update_instructions.yaml | yq w -s - sample.yaml Values starting with a hyphen (or dash) The flag terminator needs to be used to stop the app from attempting to parse the subsequent arguments as flags: yq w -- my.path -3 will output my: path: -3 Keys with dots When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Write/Update"},{"location":"write/#to-stdout","text":"Given a sample.yaml file of: b: c: 2 then yq w sample.yaml b.c cat will output: b: c: cat","title":"To Stdout"},{"location":"write/#from-stdin","text":"cat sample.yaml | yq w - b.c blah","title":"From STDIN"},{"location":"write/#adding-new-fields","text":"Any missing fields in the path will be created on the fly. Given a sample.yaml file of: b: c: 2 then yq w sample.yaml b.d[0] new thing will output: b: c: cat d: - new thing","title":"Adding new fields"},{"location":"write/#appending-value-to-an-array-field","text":"Given a sample.yaml file of: b: c: 2 d: - new thing - foo thing then yq w sample.yaml b.d[+] bar thing will output: b: c: cat d: - new thing - foo thing - bar thing Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Appending value to an array field"},{"location":"write/#multiple-documents-update-a-single-document","text":"Given a sample.yaml file of: something: else --- b: c: 2 then yq w -d1 sample.yaml b.c 5 will output: something: else --- b: c: 5","title":"Multiple Documents - update a single document"},{"location":"write/#multiple-documents-update-all-documents","text":"Given a sample.yaml file of: something: else --- b: c: 2 then yq w -d'*' sample.yaml b.c 5 will output: something: else b: c: 5 --- b: c: 5 Note that '*' is in quotes to avoid being interpreted by your shell.","title":"Multiple Documents - update all documents"},{"location":"write/#updating-files-in-place","text":"Given a sample.yaml file of: b: c: 2 then yq w -i sample.yaml b.c cat will update the sample.yaml file so that the value of 'c' is cat.","title":"Updating files in-place"},{"location":"write/#updating-multiple-values-with-a-script","text":"Given a sample.yaml file of: b: c: 2 e: - name: Billy Bob and a script update_instructions.yaml of: b.c: 3 b.e[0].name: Howdy Partner then yq w -s update_instructions.yaml sample.yaml will output: b: c: 3 e: - name: Howdy Partner And, of course, you can pipe the instructions in using '-': cat update_instructions.yaml | yq w -s - sample.yaml","title":"Updating multiple values with a script"},{"location":"write/#values-starting-with-a-hyphen-or-dash","text":"The flag terminator needs to be used to stop the app from attempting to parse the subsequent arguments as flags: yq w -- my.path -3 will output my: path: -3","title":"Values starting with a hyphen (or dash)"},{"location":"write/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"write/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Keys (and values) with leading dashes"},{"location":"snippets/niche/","text":"Keys with dots When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in --key: --value","title":"Niche"},{"location":"snippets/niche/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"snippets/niche/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in --key: --value","title":"Keys (and values) with leading dashes"},{"location":"snippets/works_with_json/","text":"This command can take a json file as input too, and will output yaml unless specified to export as json (-j)","title":"Works with json"}]}
\ No newline at end of file
+<<<<<<< HEAD
+{"config":{"lang":["en"],"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"yq yq is a lightweight and portable command-line YAML processor The aim of the project is to be the jq or sed of yaml files. Install On MacOS: brew install yq On Ubuntu and other Linux distros supporting snap packages: snap install yq On Ubuntu 16.04 or higher from Debian package: sudo add-apt-repository ppa:rmescandon/yq sudo apt update sudo apt install yq -y or, Download latest binary or alternatively: go get gopkg.in/mikefarah/yq.v2 View on GitHub","title":"Install"},{"location":"#yq","text":"yq is a lightweight and portable command-line YAML processor The aim of the project is to be the jq or sed of yaml files.","title":"yq"},{"location":"#install","text":"On MacOS: brew install yq On Ubuntu and other Linux distros supporting snap packages: snap install yq On Ubuntu 16.04 or higher from Debian package: sudo add-apt-repository ppa:rmescandon/yq sudo apt update sudo apt install yq -y or, Download latest binary or alternatively: go get gopkg.in/mikefarah/yq.v2 View on GitHub","title":"Install"},{"location":"convert/","text":"Yaml to Json To convert output to json, use the --tojson (or -j) flag. This can only be used with the read command. Given a sample.yaml file of: b: c: 2 then yq r -j sample.yaml b.c will output { b :{ c :2}} Json to Yaml To read in json, just pass in a json file instead of yaml, it will just work :) e.g given a json file { a : Easy! as one two three , b :{ c :2, d :[3,4]}} then yq r sample.json will output a: Easy! as one two three b: c: 2 d: - 3 - 4","title":"Convert"},{"location":"convert/#yaml-to-json","text":"To convert output to json, use the --tojson (or -j) flag. This can only be used with the read command. Given a sample.yaml file of: b: c: 2 then yq r -j sample.yaml b.c will output { b :{ c :2}}","title":"Yaml to Json"},{"location":"convert/#json-to-yaml","text":"To read in json, just pass in a json file instead of yaml, it will just work :) e.g given a json file { a : Easy! as one two three , b :{ c :2, d :[3,4]}} then yq r sample.json will output a: Easy! as one two three b: c: 2 d: - 3 - 4","title":"Json to Yaml"},{"location":"create/","text":"Yaml files can be created using the 'new' command. This works in the same way as the write command, but you don't pass in an existing Yaml file. Currently this does not support creating multiple documents in a single yaml file. yq n path new value Creating a simple yaml file yq n b.c cat will output: b: c: cat Creating using a create script Create scripts follow the same format as the update scripts. Given a script create_instructions.yaml of: b.c: 3 b.e[0].name: Howdy Partner then yq n -s create_instructions.yaml will output: b: c: 3 e: - name: Howdy Partner You can also pipe the instructions in: cat create_instructions.yaml | yq n -s - Keys with dots When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Create"},{"location":"create/#creating-a-simple-yaml-file","text":"yq n b.c cat will output: b: c: cat","title":"Creating a simple yaml file"},{"location":"create/#creating-using-a-create-script","text":"Create scripts follow the same format as the update scripts. Given a script create_instructions.yaml of: b.c: 3 b.e[0].name: Howdy Partner then yq n -s create_instructions.yaml will output: b: c: 3 e: - name: Howdy Partner You can also pipe the instructions in: cat create_instructions.yaml | yq n -s -","title":"Creating using a create script"},{"location":"create/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"create/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Keys (and values) with leading dashes"},{"location":"delete/","text":"yq d yaml_file path_to_delete To Stdout Given a sample.yaml file of: b: c: 2 apples: green then yq d sample.yaml b.c will output: b: apples: green From STDIN cat sample.yaml | yq d - b.c Deleting array elements Given a sample.yaml file of: b: c: - 1 - 2 - 3 then yq d sample.yaml 'b.c[1]' will output: b: c: - 1 - 3 Deleting nodes in-place Given a sample.yaml file of: b: c: 2 apples: green then yq d -i sample.yaml b.c will update the sample.yaml file so that the 'c' node is deleted Multiple Documents - delete from single document Given a sample.yaml file of: something: else field: leaveMe --- b: c: 2 field: deleteMe then yq w -d1 sample.yaml field will output: something: else field: leaveMe --- b: c: 2 Multiple Documents - delete from all documents Given a sample.yaml file of: something: else field: deleteMe --- b: c: 2 field: deleteMeToo then yq w -d'*' sample.yaml field will output: something: else --- b: c: 2 Note that '*' is in quotes to avoid being interpreted by your shell. Keys with dots When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Delete"},{"location":"delete/#to-stdout","text":"Given a sample.yaml file of: b: c: 2 apples: green then yq d sample.yaml b.c will output: b: apples: green","title":"To Stdout"},{"location":"delete/#from-stdin","text":"cat sample.yaml | yq d - b.c","title":"From STDIN"},{"location":"delete/#deleting-array-elements","text":"Given a sample.yaml file of: b: c: - 1 - 2 - 3 then yq d sample.yaml 'b.c[1]' will output: b: c: - 1 - 3","title":"Deleting array elements"},{"location":"delete/#deleting-nodes-in-place","text":"Given a sample.yaml file of: b: c: 2 apples: green then yq d -i sample.yaml b.c will update the sample.yaml file so that the 'c' node is deleted","title":"Deleting nodes in-place"},{"location":"delete/#multiple-documents-delete-from-single-document","text":"Given a sample.yaml file of: something: else field: leaveMe --- b: c: 2 field: deleteMe then yq w -d1 sample.yaml field will output: something: else field: leaveMe --- b: c: 2","title":"Multiple Documents - delete from single document"},{"location":"delete/#multiple-documents-delete-from-all-documents","text":"Given a sample.yaml file of: something: else field: deleteMe --- b: c: 2 field: deleteMeToo then yq w -d'*' sample.yaml field will output: something: else --- b: c: 2 Note that '*' is in quotes to avoid being interpreted by your shell.","title":"Multiple Documents - delete from all documents"},{"location":"delete/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"delete/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Keys (and values) with leading dashes"},{"location":"merge/","text":"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. yq m yaml_file path ... To Stdout Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m data1.yaml data2.yaml will output: a: simple b: [1, 2] c: test: 1 Updating files in-place Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m -i data1.yaml data2.yaml will update the data1.yaml file so that the value of 'c' is 'test: 1'. Overwrite values Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m -x data1.yaml data2.yaml will output: a: other b: [1, 2] c: test: 1 Overwrite values with arrays Given a data1.yaml file of: a: simple b: [1, 2] and data3.yaml file of: b: [3, 4] c: test: 2 other: true d: false then yq m -x data1.yaml data3.yaml will output: a: simple 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. 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: something: else --- a: simple b: cat and data3.yaml file of: b: dog then yq m -x -d1 data1.yaml data3.yaml will output: something: else --- a: simple b: dog 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: something: else --- a: simple b: cat and data3.yaml file of: b: dog then yq m -x -d'*' data1.yaml data3.yaml will output: b: dog something: else --- a: simple b: dog","title":"Merge"},{"location":"merge/#to-stdout","text":"Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m data1.yaml data2.yaml will output: a: simple b: [1, 2] c: test: 1","title":"To Stdout"},{"location":"merge/#updating-files-in-place","text":"Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m -i data1.yaml data2.yaml will update the data1.yaml file so that the value of 'c' is 'test: 1'.","title":"Updating files in-place"},{"location":"merge/#overwrite-values","text":"Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m -x data1.yaml data2.yaml will output: a: other b: [1, 2] c: test: 1","title":"Overwrite values"},{"location":"merge/#overwrite-values-with-arrays","text":"Given a data1.yaml file of: a: simple b: [1, 2] and data3.yaml file of: b: [3, 4] c: test: 2 other: true d: false then yq m -x data1.yaml data3.yaml will output: a: simple 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.","title":"Overwrite values with arrays"},{"location":"merge/#append-values-with-arrays","text":"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.","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 --- a: simple b: cat and data3.yaml file of: b: dog then yq m -x -d1 data1.yaml data3.yaml will output: something: else --- a: simple b: dog","title":"Multiple Documents - merge into single document"},{"location":"merge/#multiple-documents-merge-into-all-documents","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 --- a: simple b: cat and data3.yaml file of: b: dog then yq m -x -d'*' data1.yaml data3.yaml will output: b: dog something: else --- a: simple b: dog","title":"Multiple Documents - merge into all documents"},{"location":"prefix/","text":"Paths can be prefixed using the 'prefix' command. The complete yaml content will be nested inside the new prefix path. yq p yaml_file path To Stdout Given a data1.yaml file of: a: simple b: [1, 2] then yq p data1.yaml c will output: c: a: simple b: [1, 2] Arbitrary depth Given a data1.yaml file of: a: b: [1, 2] then yq p data1.yaml c.d will output: c: d: a: b: [1, 2] Updating files in-place Given a data1.yaml file of: a: simple b: [1, 2] then yq p -i data1.yaml c will update the data1.yaml file so that the path 'c' is prefixed to all other paths. Multiple Documents - prefix a single document Given a data1.yaml file of: something: else --- a: simple b: cat then yq p -d1 data1.yaml c will output: something: else --- c: a: simple b: cat Multiple Documents - prefix all documents Given a data1.yaml file of: something: else --- a: simple b: cat then yq p -d'*' data1.yaml c will output: c: something: else --- c: a: simple b: cat","title":"Prefix"},{"location":"prefix/#to-stdout","text":"Given a data1.yaml file of: a: simple b: [1, 2] then yq p data1.yaml c will output: c: a: simple b: [1, 2]","title":"To Stdout"},{"location":"prefix/#arbitrary-depth","text":"Given a data1.yaml file of: a: b: [1, 2] then yq p data1.yaml c.d will output: c: d: a: b: [1, 2]","title":"Arbitrary depth"},{"location":"prefix/#updating-files-in-place","text":"Given a data1.yaml file of: a: simple b: [1, 2] then yq p -i data1.yaml c will update the data1.yaml file so that the path 'c' is prefixed to all other paths.","title":"Updating files in-place"},{"location":"prefix/#multiple-documents-prefix-a-single-document","text":"Given a data1.yaml file of: something: else --- a: simple b: cat then yq p -d1 data1.yaml c will output: something: else --- c: a: simple b: cat","title":"Multiple Documents - prefix a single document"},{"location":"prefix/#multiple-documents-prefix-all-documents","text":"Given a data1.yaml file of: something: else --- a: simple b: cat then yq p -d'*' data1.yaml c will output: c: something: else --- c: a: simple b: cat","title":"Multiple Documents - prefix all documents"},{"location":"read/","text":"yq r yaml_file|json_file path This command can take a json file as input too, and will output yaml unless specified to export as json (-j) Basic Given a sample.yaml file of: b: c: 2 then yq r sample.yaml b.c will output the value of '2'. From Stdin Given a sample.yaml file of: cat sample.yaml | yq r - b.c will output the value of '2'. Splat Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples then yq r sample.yaml bob.*.cats will output - bananas - apples Multiple Documents - specify a single document Given a sample.yaml file of: something: else --- b: c: 2 then yq r -d1 sample.yaml b.c will output the value of '2'. Multiple Documents - read all documents Reading all documents will return the result as an array. This can be converted to json using the '-j' flag if desired. Given a sample.yaml file of: name: Fred age: 22 --- name: Stella age: 23 --- name: Android age: 232 then yq r -d'*' sample.yaml name will output: - Fred - Stella - Android Arrays You can give an index to access a specific element: e.g.: given a sample file of b: e: - name: fred value: 3 - name: sam value: 4 then yq r sample.yaml 'b.e[1].name' will output 'sam' Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Array Splat e.g.: given a sample file of b: e: - name: fred value: 3 - name: sam value: 4 then yq r sample.yaml 'b.e[*].name' will output: - fred - sam Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys with dots When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Read"},{"location":"read/#basic","text":"Given a sample.yaml file of: b: c: 2 then yq r sample.yaml b.c will output the value of '2'.","title":"Basic"},{"location":"read/#from-stdin","text":"Given a sample.yaml file of: cat sample.yaml | yq r - b.c will output the value of '2'.","title":"From Stdin"},{"location":"read/#splat","text":"Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples then yq r sample.yaml bob.*.cats will output - bananas - apples","title":"Splat"},{"location":"read/#multiple-documents-specify-a-single-document","text":"Given a sample.yaml file of: something: else --- b: c: 2 then yq r -d1 sample.yaml b.c will output the value of '2'.","title":"Multiple Documents - specify a single document"},{"location":"read/#multiple-documents-read-all-documents","text":"Reading all documents will return the result as an array. This can be converted to json using the '-j' flag if desired. Given a sample.yaml file of: name: Fred age: 22 --- name: Stella age: 23 --- name: Android age: 232 then yq r -d'*' sample.yaml name will output: - Fred - Stella - Android","title":"Multiple Documents - read all documents"},{"location":"read/#arrays","text":"You can give an index to access a specific element: e.g.: given a sample file of b: e: - name: fred value: 3 - name: sam value: 4 then yq r sample.yaml 'b.e[1].name' will output 'sam' Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Arrays"},{"location":"read/#array-splat","text":"e.g.: given a sample file of b: e: - name: fred value: 3 - name: sam value: 4 then yq r sample.yaml 'b.e[*].name' will output: - fred - sam Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Array Splat"},{"location":"read/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"read/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Keys (and values) with leading dashes"},{"location":"write/","text":"yq w yaml_file path new value To Stdout Given a sample.yaml file of: b: c: 2 then yq w sample.yaml b.c cat will output: b: c: cat From STDIN cat sample.yaml | yq w - b.c blah Adding new fields Any missing fields in the path will be created on the fly. Given a sample.yaml file of: b: c: 2 then yq w sample.yaml b.d[0] new thing will output: b: c: cat d: - new thing Appending value to an array field Given a sample.yaml file of: b: c: 2 d: - new thing - foo thing then yq w sample.yaml b.d[+] bar thing will output: b: c: cat d: - new thing - foo thing - bar thing Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Multiple Documents - update a single document Given a sample.yaml file of: something: else --- b: c: 2 then yq w -d1 sample.yaml b.c 5 will output: something: else --- b: c: 5 Multiple Documents - update all documents Given a sample.yaml file of: something: else --- b: c: 2 then yq w -d'*' sample.yaml b.c 5 will output: something: else b: c: 5 --- b: c: 5 Note that '*' is in quotes to avoid being interpreted by your shell. Updating files in-place Given a sample.yaml file of: b: c: 2 then yq w -i sample.yaml b.c cat will update the sample.yaml file so that the value of 'c' is cat. Updating multiple values with a script Given a sample.yaml file of: b: c: 2 e: - name: Billy Bob and a script update_instructions.yaml of: b.c: 3 b.e[0].name: Howdy Partner then yq w -s update_instructions.yaml sample.yaml will output: b: c: 3 e: - name: Howdy Partner And, of course, you can pipe the instructions in using '-': cat update_instructions.yaml | yq w -s - sample.yaml Values starting with a hyphen (or dash) The flag terminator needs to be used to stop the app from attempting to parse the subsequent arguments as flags: yq w -- my.path -3 will output my: path: -3 Keys with dots When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Write/Update"},{"location":"write/#to-stdout","text":"Given a sample.yaml file of: b: c: 2 then yq w sample.yaml b.c cat will output: b: c: cat","title":"To Stdout"},{"location":"write/#from-stdin","text":"cat sample.yaml | yq w - b.c blah","title":"From STDIN"},{"location":"write/#adding-new-fields","text":"Any missing fields in the path will be created on the fly. Given a sample.yaml file of: b: c: 2 then yq w sample.yaml b.d[0] new thing will output: b: c: cat d: - new thing","title":"Adding new fields"},{"location":"write/#appending-value-to-an-array-field","text":"Given a sample.yaml file of: b: c: 2 d: - new thing - foo thing then yq w sample.yaml b.d[+] bar thing will output: b: c: cat d: - new thing - foo thing - bar thing Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Appending value to an array field"},{"location":"write/#multiple-documents-update-a-single-document","text":"Given a sample.yaml file of: something: else --- b: c: 2 then yq w -d1 sample.yaml b.c 5 will output: something: else --- b: c: 5","title":"Multiple Documents - update a single document"},{"location":"write/#multiple-documents-update-all-documents","text":"Given a sample.yaml file of: something: else --- b: c: 2 then yq w -d'*' sample.yaml b.c 5 will output: something: else b: c: 5 --- b: c: 5 Note that '*' is in quotes to avoid being interpreted by your shell.","title":"Multiple Documents - update all documents"},{"location":"write/#updating-files-in-place","text":"Given a sample.yaml file of: b: c: 2 then yq w -i sample.yaml b.c cat will update the sample.yaml file so that the value of 'c' is cat.","title":"Updating files in-place"},{"location":"write/#updating-multiple-values-with-a-script","text":"Given a sample.yaml file of: b: c: 2 e: - name: Billy Bob and a script update_instructions.yaml of: b.c: 3 b.e[0].name: Howdy Partner then yq w -s update_instructions.yaml sample.yaml will output: b: c: 3 e: - name: Howdy Partner And, of course, you can pipe the instructions in using '-': cat update_instructions.yaml | yq w -s - sample.yaml","title":"Updating multiple values with a script"},{"location":"write/#values-starting-with-a-hyphen-or-dash","text":"The flag terminator needs to be used to stop the app from attempting to parse the subsequent arguments as flags: yq w -- my.path -3 will output my: path: -3","title":"Values starting with a hyphen (or dash)"},{"location":"write/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"write/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Keys (and values) with leading dashes"},{"location":"snippets/niche/","text":"Keys with dots When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in --key: --value","title":"Niche"},{"location":"snippets/niche/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"snippets/niche/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in --key: --value","title":"Keys (and values) with leading dashes"},{"location":"snippets/works_with_json/","text":"This command can take a json file as input too, and will output yaml unless specified to export as json (-j)","title":"Works with json"}]}
+=======
+{"config":{"lang":["en"],"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"yq \u00b6 yq is a lightweight and portable command-line YAML processor The aim of the project is to be the jq or sed of yaml files. Install \u00b6 On MacOS: brew install yq On Ubuntu and other Linux distros supporting snap packages: snap install yq On Ubuntu 16.04 or higher from Debian package: sudo add-apt-repository ppa:rmescandon/yq sudo apt update sudo apt install yq -y or, Download latest binary or alternatively: go get gopkg.in/mikefarah/yq.v2 View on GitHub","title":"Install"},{"location":"#yq","text":"yq is a lightweight and portable command-line YAML processor The aim of the project is to be the jq or sed of yaml files.","title":"yq"},{"location":"#install","text":"On MacOS: brew install yq On Ubuntu and other Linux distros supporting snap packages: snap install yq On Ubuntu 16.04 or higher from Debian package: sudo add-apt-repository ppa:rmescandon/yq sudo apt update sudo apt install yq -y or, Download latest binary or alternatively: go get gopkg.in/mikefarah/yq.v2 View on GitHub","title":"Install"},{"location":"convert/","text":"Yaml to Json \u00b6 To convert output to json, use the --tojson (or -j) flag. This can only be used with the read command. Given a sample.yaml file of: b: c: 2 then yq r -j sample.yaml b.c will output {\"b\":{\"c\":2}} Json to Yaml \u00b6 To read in json, just pass in a json file instead of yaml, it will just work :) e.g given a json file {\"a\":\"Easy! as one two three\",\"b\":{\"c\":2,\"d\":[3,4]}} then yq r sample.json will output a: Easy! as one two three b: c: 2 d: - 3 - 4","title":"Convert"},{"location":"convert/#yaml-to-json","text":"To convert output to json, use the --tojson (or -j) flag. This can only be used with the read command. Given a sample.yaml file of: b: c: 2 then yq r -j sample.yaml b.c will output {\"b\":{\"c\":2}}","title":"Yaml to Json"},{"location":"convert/#json-to-yaml","text":"To read in json, just pass in a json file instead of yaml, it will just work :) e.g given a json file {\"a\":\"Easy! as one two three\",\"b\":{\"c\":2,\"d\":[3,4]}} then yq r sample.json will output a: Easy! as one two three b: c: 2 d: - 3 - 4","title":"Json to Yaml"},{"location":"create/","text":"Yaml files can be created using the 'new' command. This works in the same way as the write command, but you don't pass in an existing Yaml file. Currently this does not support creating multiple documents in a single yaml file. yq n Creating a simple yaml file \u00b6 yq n b.c cat will output: b: c: cat Creating using a create script \u00b6 Create scripts follow the same format as the update scripts. Given a script create_instructions.yaml of: b.c: 3 b.e[0].name: Howdy Partner then yq n -s create_instructions.yaml will output: b: c: 3 e: - name: Howdy Partner You can also pipe the instructions in: cat create_instructions.yaml | yq n -s - Keys with dots \u00b6 When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes \u00b6 If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Create"},{"location":"create/#creating-a-simple-yaml-file","text":"yq n b.c cat will output: b: c: cat","title":"Creating a simple yaml file"},{"location":"create/#creating-using-a-create-script","text":"Create scripts follow the same format as the update scripts. Given a script create_instructions.yaml of: b.c: 3 b.e[0].name: Howdy Partner then yq n -s create_instructions.yaml will output: b: c: 3 e: - name: Howdy Partner You can also pipe the instructions in: cat create_instructions.yaml | yq n -s -","title":"Creating using a create script"},{"location":"create/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"create/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Keys (and values) with leading dashes"},{"location":"delete/","text":"yq d To Stdout \u00b6 Given a sample.yaml file of: b: c: 2 apples: green then yq d sample.yaml b.c will output: b: apples: green From STDIN \u00b6 cat sample.yaml | yq d - b.c Deleting array elements \u00b6 Given a sample.yaml file of: b: c: - 1 - 2 - 3 then yq d sample.yaml 'b.c[1]' will output: b: c: - 1 - 3 Deleting nodes in-place \u00b6 Given a sample.yaml file of: b: c: 2 apples: green then yq d -i sample.yaml b.c will update the sample.yaml file so that the 'c' node is deleted Splat \u00b6 Given a sample.yaml file of: --- bob: item1: cats: bananas dogs: woof item2: cats: apples dogs: woof2 thing: cats: oranges dogs: woof3 then yq d sample.yaml bob.*.cats will output: --- bob: item1: dogs: woof item2: dogs: woof2 thing: dogs: woof3 Prefix Splat \u00b6 Given a sample.yaml file of: --- bob: item1: cats: bananas dogs: woof item2: cats: apples dogs: woof2 thing: cats: oranges dogs: woof3 then yq d sample.yaml bob.item*.cats will output: --- bob: item1: dogs: woof item2: dogs: woof2 thing: cats: oranges dogs: woof3 Array Splat \u00b6 Given a sample.yaml file of: --- bob: - cats: bananas dogs: woof - cats: apples dogs: woof2 - cats: oranges dogs: woof3 then yq d sample.yaml bob.[*].cats will output: --- bob: - dogs: woof - dogs: woof2 - dogs: woof3 Multiple Documents - delete from single document \u00b6 Given a sample.yaml file of: something: else field: leaveMe --- b: c: 2 field: deleteMe then yq w -d1 sample.yaml field will output: something: else field: leaveMe --- b: c: 2 Multiple Documents - delete from all documents \u00b6 Given a sample.yaml file of: something: else field: deleteMe --- b: c: 2 field: deleteMeToo then yq w -d'*' sample.yaml field will output: something: else --- b: c: 2 Note that '*' is in quotes to avoid being interpreted by your shell. Keys with dots \u00b6 When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes \u00b6 If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Delete"},{"location":"delete/#to-stdout","text":"Given a sample.yaml file of: b: c: 2 apples: green then yq d sample.yaml b.c will output: b: apples: green","title":"To Stdout"},{"location":"delete/#from-stdin","text":"cat sample.yaml | yq d - b.c","title":"From STDIN"},{"location":"delete/#deleting-array-elements","text":"Given a sample.yaml file of: b: c: - 1 - 2 - 3 then yq d sample.yaml 'b.c[1]' will output: b: c: - 1 - 3","title":"Deleting array elements"},{"location":"delete/#deleting-nodes-in-place","text":"Given a sample.yaml file of: b: c: 2 apples: green then yq d -i sample.yaml b.c will update the sample.yaml file so that the 'c' node is deleted","title":"Deleting nodes in-place"},{"location":"delete/#splat","text":"Given a sample.yaml file of: --- bob: item1: cats: bananas dogs: woof item2: cats: apples dogs: woof2 thing: cats: oranges dogs: woof3 then yq d sample.yaml bob.*.cats will output: --- bob: item1: dogs: woof item2: dogs: woof2 thing: dogs: woof3","title":"Splat"},{"location":"delete/#prefix-splat","text":"Given a sample.yaml file of: --- bob: item1: cats: bananas dogs: woof item2: cats: apples dogs: woof2 thing: cats: oranges dogs: woof3 then yq d sample.yaml bob.item*.cats will output: --- bob: item1: dogs: woof item2: dogs: woof2 thing: cats: oranges dogs: woof3","title":"Prefix Splat"},{"location":"delete/#array-splat","text":"Given a sample.yaml file of: --- bob: - cats: bananas dogs: woof - cats: apples dogs: woof2 - cats: oranges dogs: woof3 then yq d sample.yaml bob.[*].cats will output: --- bob: - dogs: woof - dogs: woof2 - dogs: woof3","title":"Array Splat"},{"location":"delete/#multiple-documents-delete-from-single-document","text":"Given a sample.yaml file of: something: else field: leaveMe --- b: c: 2 field: deleteMe then yq w -d1 sample.yaml field will output: something: else field: leaveMe --- b: c: 2","title":"Multiple Documents - delete from single document"},{"location":"delete/#multiple-documents-delete-from-all-documents","text":"Given a sample.yaml file of: something: else field: deleteMe --- b: c: 2 field: deleteMeToo then yq w -d'*' sample.yaml field will output: something: else --- b: c: 2 Note that '*' is in quotes to avoid being interpreted by your shell.","title":"Multiple Documents - delete from all documents"},{"location":"delete/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"delete/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Keys (and values) with leading dashes"},{"location":"merge/","text":"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. yq m ... To Stdout \u00b6 Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m data1.yaml data2.yaml will output: a: simple b: [1, 2] c: test: 1 Updating files in-place \u00b6 Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m -i data1.yaml data2.yaml will update the data1.yaml file so that the value of 'c' is 'test: 1'. Overwrite values \u00b6 Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m -x data1.yaml data2.yaml will output: a: other b: [1, 2] c: test: 1 Overwrite values with arrays \u00b6 Given a data1.yaml file of: a: simple b: [1, 2] and data3.yaml file of: b: [3, 4] c: test: 2 other: true d: false then yq m -x data1.yaml data3.yaml will output: a: simple 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. Append values with arrays \u00b6 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 \u00b6 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 --- a: simple b: cat and data3.yaml file of: b: dog then yq m -x -d1 data1.yaml data3.yaml will output: something: else --- a: simple b: dog Multiple Documents - merge into all documents \u00b6 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 --- a: simple b: cat and data3.yaml file of: b: dog then yq m -x -d'*' data1.yaml data3.yaml will output: b: dog something: else --- a: simple b: dog","title":"Merge"},{"location":"merge/#to-stdout","text":"Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m data1.yaml data2.yaml will output: a: simple b: [1, 2] c: test: 1","title":"To Stdout"},{"location":"merge/#updating-files-in-place","text":"Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m -i data1.yaml data2.yaml will update the data1.yaml file so that the value of 'c' is 'test: 1'.","title":"Updating files in-place"},{"location":"merge/#overwrite-values","text":"Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m -x data1.yaml data2.yaml will output: a: other b: [1, 2] c: test: 1","title":"Overwrite values"},{"location":"merge/#overwrite-values-with-arrays","text":"Given a data1.yaml file of: a: simple b: [1, 2] and data3.yaml file of: b: [3, 4] c: test: 2 other: true d: false then yq m -x data1.yaml data3.yaml will output: a: simple 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.","title":"Overwrite values with arrays"},{"location":"merge/#append-values-with-arrays","text":"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.","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 --- a: simple b: cat and data3.yaml file of: b: dog then yq m -x -d1 data1.yaml data3.yaml will output: something: else --- a: simple b: dog","title":"Multiple Documents - merge into single document"},{"location":"merge/#multiple-documents-merge-into-all-documents","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 --- a: simple b: cat and data3.yaml file of: b: dog then yq m -x -d'*' data1.yaml data3.yaml will output: b: dog something: else --- a: simple b: dog","title":"Multiple Documents - merge into all documents"},{"location":"prefix/","text":"Paths can be prefixed using the 'prefix' command. The complete yaml content will be nested inside the new prefix path. yq p To Stdout \u00b6 Given a data1.yaml file of: a: simple b: [1, 2] then yq p data1.yaml c will output: c: a: simple b: [1, 2] Arbitrary depth \u00b6 Given a data1.yaml file of: a: b: [1, 2] then yq p data1.yaml c.d will output: c: d: a: b: [1, 2] Updating files in-place \u00b6 Given a data1.yaml file of: a: simple b: [1, 2] then yq p -i data1.yaml c will update the data1.yaml file so that the path 'c' is prefixed to all other paths. Multiple Documents - prefix a single document \u00b6 Given a data1.yaml file of: something: else --- a: simple b: cat then yq p -d1 data1.yaml c will output: something: else --- c: a: simple b: cat Multiple Documents - prefix all documents \u00b6 Given a data1.yaml file of: something: else --- a: simple b: cat then yq p -d'*' data1.yaml c will output: c: something: else --- c: a: simple b: cat","title":"Prefix"},{"location":"prefix/#to-stdout","text":"Given a data1.yaml file of: a: simple b: [1, 2] then yq p data1.yaml c will output: c: a: simple b: [1, 2]","title":"To Stdout"},{"location":"prefix/#arbitrary-depth","text":"Given a data1.yaml file of: a: b: [1, 2] then yq p data1.yaml c.d will output: c: d: a: b: [1, 2]","title":"Arbitrary depth"},{"location":"prefix/#updating-files-in-place","text":"Given a data1.yaml file of: a: simple b: [1, 2] then yq p -i data1.yaml c will update the data1.yaml file so that the path 'c' is prefixed to all other paths.","title":"Updating files in-place"},{"location":"prefix/#multiple-documents-prefix-a-single-document","text":"Given a data1.yaml file of: something: else --- a: simple b: cat then yq p -d1 data1.yaml c will output: something: else --- c: a: simple b: cat","title":"Multiple Documents - prefix a single document"},{"location":"prefix/#multiple-documents-prefix-all-documents","text":"Given a data1.yaml file of: something: else --- a: simple b: cat then yq p -d'*' data1.yaml c will output: c: something: else --- c: a: simple b: cat","title":"Multiple Documents - prefix all documents"},{"location":"read/","text":"yq r This command can take a json file as input too, and will output yaml unless specified to export as json (-j) Basic \u00b6 Given a sample.yaml file of: b: c: 2 then yq r sample.yaml b.c will output the value of '2'. From Stdin \u00b6 Given a sample.yaml file of: cat sample.yaml | yq r - b.c will output the value of '2'. Splat \u00b6 Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples thing: cats: oranges then yq r sample.yaml bob.*.cats will output - bananas - apples - oranges Prefix Splat \u00b6 Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples thing: cats: oranges then yq r sample.yaml bob.item*.cats will output - bananas - apples Multiple Documents - specify a single document \u00b6 Given a sample.yaml file of: something: else --- b: c: 2 then yq r -d1 sample.yaml b.c will output the value of '2'. Multiple Documents - read all documents \u00b6 Reading all documents will return the result as an array. This can be converted to json using the '-j' flag if desired. Given a sample.yaml file of: name: Fred age: 22 --- name: Stella age: 23 --- name: Android age: 232 then yq r -d'*' sample.yaml name will output: - Fred - Stella - Android Arrays \u00b6 You can give an index to access a specific element: e.g.: given a sample file of b: e: - name: fred value: 3 - name: sam value: 4 then yq r sample.yaml 'b.e[1].name' will output 'sam' Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Array Splat \u00b6 e.g.: given a sample file of b: e: - name: fred value: 3 - name: sam value: 4 then yq r sample.yaml 'b.e[*].name' will output: - fred - sam Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys with dots \u00b6 When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes \u00b6 If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Read"},{"location":"read/#basic","text":"Given a sample.yaml file of: b: c: 2 then yq r sample.yaml b.c will output the value of '2'.","title":"Basic"},{"location":"read/#from-stdin","text":"Given a sample.yaml file of: cat sample.yaml | yq r - b.c will output the value of '2'.","title":"From Stdin"},{"location":"read/#splat","text":"Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples thing: cats: oranges then yq r sample.yaml bob.*.cats will output - bananas - apples - oranges","title":"Splat"},{"location":"read/#prefix-splat","text":"Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples thing: cats: oranges then yq r sample.yaml bob.item*.cats will output - bananas - apples","title":"Prefix Splat"},{"location":"read/#multiple-documents-specify-a-single-document","text":"Given a sample.yaml file of: something: else --- b: c: 2 then yq r -d1 sample.yaml b.c will output the value of '2'.","title":"Multiple Documents - specify a single document"},{"location":"read/#multiple-documents-read-all-documents","text":"Reading all documents will return the result as an array. This can be converted to json using the '-j' flag if desired. Given a sample.yaml file of: name: Fred age: 22 --- name: Stella age: 23 --- name: Android age: 232 then yq r -d'*' sample.yaml name will output: - Fred - Stella - Android","title":"Multiple Documents - read all documents"},{"location":"read/#arrays","text":"You can give an index to access a specific element: e.g.: given a sample file of b: e: - name: fred value: 3 - name: sam value: 4 then yq r sample.yaml 'b.e[1].name' will output 'sam' Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Arrays"},{"location":"read/#array-splat","text":"e.g.: given a sample file of b: e: - name: fred value: 3 - name: sam value: 4 then yq r sample.yaml 'b.e[*].name' will output: - fred - sam Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Array Splat"},{"location":"read/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"read/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Keys (and values) with leading dashes"},{"location":"write/","text":"yq w To Stdout \u00b6 Given a sample.yaml file of: b: c: 2 then yq w sample.yaml b.c cat will output: b: c: cat From STDIN \u00b6 cat sample.yaml | yq w - b.c blah Adding new fields \u00b6 Any missing fields in the path will be created on the fly. Given a sample.yaml file of: b: c: 2 then yq w sample.yaml b.d[0] \"new thing\" will output: b: c: cat d: - new thing Splat \u00b6 Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples thing: cats: oranges then yq w sample.yaml bob.*.cats meow will output: --- bob: item1: cats: meow item2: cats: meow thing: cats: meow Prefix Splat \u00b6 Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples thing: cats: oranges then yq w sample.yaml bob.item*.cats meow will output: --- bob: item1: cats: meow item2: cats: meow thing: cats: oranges Array Splat \u00b6 Given a sample.yaml file of: --- bob: - cats: bananas - cats: apples - cats: oranges then yq w sample.yaml bob[*].cats meow will output: --- bob: - cats: meow - cats: meow - cats: meow Appending value to an array field \u00b6 Given a sample.yaml file of: b: c: 2 d: - new thing - foo thing then yq w sample.yaml \"b.d[+]\" \"bar thing\" will output: b: c: cat d: - new thing - foo thing - bar thing Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Multiple Documents - update a single document \u00b6 Given a sample.yaml file of: something: else --- b: c: 2 then yq w -d1 sample.yaml b.c 5 will output: something: else --- b: c: 5 Multiple Documents - update all documents \u00b6 Given a sample.yaml file of: something: else --- b: c: 2 then yq w -d'*' sample.yaml b.c 5 will output: something: else b: c: 5 --- b: c: 5 Note that '*' is in quotes to avoid being interpreted by your shell. Updating files in-place \u00b6 Given a sample.yaml file of: b: c: 2 then yq w -i sample.yaml b.c cat will update the sample.yaml file so that the value of 'c' is cat. Updating multiple values with a script \u00b6 Given a sample.yaml file of: b: c: 2 e: - name: Billy Bob and a script update_instructions.yaml of: b.c: 3 b.e[0].name: Howdy Partner then yq w -s update_instructions.yaml sample.yaml will output: b: c: 3 e: - name: Howdy Partner And, of course, you can pipe the instructions in using '-': cat update_instructions.yaml | yq w -s - sample.yaml Values starting with a hyphen (or dash) \u00b6 The flag terminator needs to be used to stop the app from attempting to parse the subsequent arguments as flags: yq w -- my.path -3 will output my: path: -3 Keys with dots \u00b6 When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes \u00b6 If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Write/Update"},{"location":"write/#to-stdout","text":"Given a sample.yaml file of: b: c: 2 then yq w sample.yaml b.c cat will output: b: c: cat","title":"To Stdout"},{"location":"write/#from-stdin","text":"cat sample.yaml | yq w - b.c blah","title":"From STDIN"},{"location":"write/#adding-new-fields","text":"Any missing fields in the path will be created on the fly. Given a sample.yaml file of: b: c: 2 then yq w sample.yaml b.d[0] \"new thing\" will output: b: c: cat d: - new thing","title":"Adding new fields"},{"location":"write/#splat","text":"Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples thing: cats: oranges then yq w sample.yaml bob.*.cats meow will output: --- bob: item1: cats: meow item2: cats: meow thing: cats: meow","title":"Splat"},{"location":"write/#prefix-splat","text":"Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples thing: cats: oranges then yq w sample.yaml bob.item*.cats meow will output: --- bob: item1: cats: meow item2: cats: meow thing: cats: oranges","title":"Prefix Splat"},{"location":"write/#array-splat","text":"Given a sample.yaml file of: --- bob: - cats: bananas - cats: apples - cats: oranges then yq w sample.yaml bob[*].cats meow will output: --- bob: - cats: meow - cats: meow - cats: meow","title":"Array Splat"},{"location":"write/#appending-value-to-an-array-field","text":"Given a sample.yaml file of: b: c: 2 d: - new thing - foo thing then yq w sample.yaml \"b.d[+]\" \"bar thing\" will output: b: c: cat d: - new thing - foo thing - bar thing Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Appending value to an array field"},{"location":"write/#multiple-documents-update-a-single-document","text":"Given a sample.yaml file of: something: else --- b: c: 2 then yq w -d1 sample.yaml b.c 5 will output: something: else --- b: c: 5","title":"Multiple Documents - update a single document"},{"location":"write/#multiple-documents-update-all-documents","text":"Given a sample.yaml file of: something: else --- b: c: 2 then yq w -d'*' sample.yaml b.c 5 will output: something: else b: c: 5 --- b: c: 5 Note that '*' is in quotes to avoid being interpreted by your shell.","title":"Multiple Documents - update all documents"},{"location":"write/#updating-files-in-place","text":"Given a sample.yaml file of: b: c: 2 then yq w -i sample.yaml b.c cat will update the sample.yaml file so that the value of 'c' is cat.","title":"Updating files in-place"},{"location":"write/#updating-multiple-values-with-a-script","text":"Given a sample.yaml file of: b: c: 2 e: - name: Billy Bob and a script update_instructions.yaml of: b.c: 3 b.e[0].name: Howdy Partner then yq w -s update_instructions.yaml sample.yaml will output: b: c: 3 e: - name: Howdy Partner And, of course, you can pipe the instructions in using '-': cat update_instructions.yaml | yq w -s - sample.yaml","title":"Updating multiple values with a script"},{"location":"write/#values-starting-with-a-hyphen-or-dash","text":"The flag terminator needs to be used to stop the app from attempting to parse the subsequent arguments as flags: yq w -- my.path -3 will output my: path: -3","title":"Values starting with a hyphen (or dash)"},{"location":"write/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"write/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Keys (and values) with leading dashes"},{"location":"snippets/niche/","text":"Keys with dots \u00b6 When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes \u00b6 If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in --key: --value","title":"Niche"},{"location":"snippets/niche/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"snippets/niche/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in --key: --value","title":"Keys (and values) with leading dashes"},{"location":"snippets/works_with_json/","text":"This command can take a json file as input too, and will output yaml unless specified to export as json (-j)","title":"Works with json"}]}
+>>>>>>> Updated instructions
diff --git a/docs/write/index.html b/docs/write/index.html
index 08507916..c3907db1 100644
--- a/docs/write/index.html
+++ b/docs/write/index.html
@@ -294,6 +294,27 @@
Adding new fields
+
+
+
@@ -579,6 +621,81 @@
- new thing
+Splat
+Given a sample.yaml file of:
+---
+bob:
+ item1:
+ cats: bananas
+ item2:
+ cats: apples
+ thing:
+ cats: oranges
+
+
+then
+yq w sample.yaml bob.*.cats meow
+
+
+will output:
+---
+bob:
+ item1:
+ cats: meow
+ item2:
+ cats: meow
+ thing:
+ cats: meow
+
+
+Prefix Splat
+Given a sample.yaml file of:
+---
+bob:
+ item1:
+ cats: bananas
+ item2:
+ cats: apples
+ thing:
+ cats: oranges
+
+
+then
+yq w sample.yaml bob.item*.cats meow
+
+
+will output:
+---
+bob:
+ item1:
+ cats: meow
+ item2:
+ cats: meow
+ thing:
+ cats: oranges
+
+
+Array Splat
+Given a sample.yaml file of:
+---
+bob:
+- cats: bananas
+- cats: apples
+- cats: oranges
+
+
+then
+yq w sample.yaml bob[*].cats meow
+
+
+will output:
+---
+bob:
+- cats: meow
+- cats: meow
+- cats: meow
+
+
Appending value to an array field
Given a sample.yaml file of:
b:
diff --git a/mkdocs/delete.md b/mkdocs/delete.md
index 7a67d103..f1f7883e 100644
--- a/mkdocs/delete.md
+++ b/mkdocs/delete.md
@@ -59,6 +59,93 @@ yq d -i sample.yaml b.c
will update the sample.yaml file so that the 'c' node is deleted
+### Splat
+Given a sample.yaml file of:
+```yaml
+---
+bob:
+ item1:
+ cats: bananas
+ dogs: woof
+ item2:
+ cats: apples
+ dogs: woof2
+ thing:
+ cats: oranges
+ dogs: woof3
+```
+then
+```bash
+yq d sample.yaml bob.*.cats
+```
+will output:
+```yaml
+---
+bob:
+ item1:
+ dogs: woof
+ item2:
+ dogs: woof2
+ thing:
+ dogs: woof3
+```
+
+### Prefix Splat
+Given a sample.yaml file of:
+```yaml
+---
+bob:
+ item1:
+ cats: bananas
+ dogs: woof
+ item2:
+ cats: apples
+ dogs: woof2
+ thing:
+ cats: oranges
+ dogs: woof3
+```
+then
+```bash
+yq d sample.yaml bob.item*.cats
+```
+will output:
+```yaml
+---
+bob:
+ item1:
+ dogs: woof
+ item2:
+ dogs: woof2
+ thing:
+ cats: oranges
+ dogs: woof3
+```
+
+### Array Splat
+Given a sample.yaml file of:
+```yaml
+---
+bob:
+- cats: bananas
+ dogs: woof
+- cats: apples
+ dogs: woof2
+- cats: oranges
+ dogs: woof3
+```
+then
+```bash
+yq d sample.yaml bob.[*].cats
+```
+will output:
+```yaml
+---
+bob:
+- dogs: woof
+- dogs: woof2
+- dogs: woof3
+```
### Multiple Documents - delete from single document
Given a sample.yaml file of:
diff --git a/mkdocs/write.md b/mkdocs/write.md
index d06feaa2..f80aad69 100644
--- a/mkdocs/write.md
+++ b/mkdocs/write.md
@@ -99,6 +99,28 @@ bob:
cats: oranges
```
+### Array Splat
+Given a sample.yaml file of:
+```yaml
+---
+bob:
+- cats: bananas
+- cats: apples
+- cats: oranges
+```
+then
+```bash
+yq w sample.yaml bob[*].cats meow
+```
+will output:
+```yaml
+---
+bob:
+- cats: meow
+- cats: meow
+- cats: meow
+```
+
### Appending value to an array field
Given a sample.yaml file of:
```yaml
From e9b8265ca3c95f6de28e30e4364dad47a2063dff Mon Sep 17 00:00:00 2001
From: Mike Farah
Date: Thu, 16 May 2019 14:57:34 +1000
Subject: [PATCH 39/54] Updated docs re creating a new array
---
docs/create/index.html | 2 +-
docs/search/search_index.json | 6 +-----
docs/sitemap.xml | 16 ++++++++--------
docs/sitemap.xml.gz | Bin 201 -> 201 bytes
docs/write/index.html | 4 ++--
mkdocs/create.md | 2 +-
mkdocs/write.md | 4 ++--
7 files changed, 15 insertions(+), 19 deletions(-)
diff --git a/docs/create/index.html b/docs/create/index.html
index c57a53ce..643060d3 100644
--- a/docs/create/index.html
+++ b/docs/create/index.html
@@ -458,7 +458,7 @@
Create scripts follow the same format as the update scripts.
Given a script create_instructions.yaml of:
b.c: 3
-b.e[0].name: Howdy Partner
+b.e[+].name: Howdy Partner
then
diff --git a/docs/search/search_index.json b/docs/search/search_index.json
index c679dc79..0b3182c6 100644
--- a/docs/search/search_index.json
+++ b/docs/search/search_index.json
@@ -1,5 +1 @@
-<<<<<<< HEAD
-{"config":{"lang":["en"],"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"yq yq is a lightweight and portable command-line YAML processor The aim of the project is to be the jq or sed of yaml files. Install On MacOS: brew install yq On Ubuntu and other Linux distros supporting snap packages: snap install yq On Ubuntu 16.04 or higher from Debian package: sudo add-apt-repository ppa:rmescandon/yq sudo apt update sudo apt install yq -y or, Download latest binary or alternatively: go get gopkg.in/mikefarah/yq.v2 View on GitHub","title":"Install"},{"location":"#yq","text":"yq is a lightweight and portable command-line YAML processor The aim of the project is to be the jq or sed of yaml files.","title":"yq"},{"location":"#install","text":"On MacOS: brew install yq On Ubuntu and other Linux distros supporting snap packages: snap install yq On Ubuntu 16.04 or higher from Debian package: sudo add-apt-repository ppa:rmescandon/yq sudo apt update sudo apt install yq -y or, Download latest binary or alternatively: go get gopkg.in/mikefarah/yq.v2 View on GitHub","title":"Install"},{"location":"convert/","text":"Yaml to Json To convert output to json, use the --tojson (or -j) flag. This can only be used with the read command. Given a sample.yaml file of: b: c: 2 then yq r -j sample.yaml b.c will output { b :{ c :2}} Json to Yaml To read in json, just pass in a json file instead of yaml, it will just work :) e.g given a json file { a : Easy! as one two three , b :{ c :2, d :[3,4]}} then yq r sample.json will output a: Easy! as one two three b: c: 2 d: - 3 - 4","title":"Convert"},{"location":"convert/#yaml-to-json","text":"To convert output to json, use the --tojson (or -j) flag. This can only be used with the read command. Given a sample.yaml file of: b: c: 2 then yq r -j sample.yaml b.c will output { b :{ c :2}}","title":"Yaml to Json"},{"location":"convert/#json-to-yaml","text":"To read in json, just pass in a json file instead of yaml, it will just work :) e.g given a json file { a : Easy! as one two three , b :{ c :2, d :[3,4]}} then yq r sample.json will output a: Easy! as one two three b: c: 2 d: - 3 - 4","title":"Json to Yaml"},{"location":"create/","text":"Yaml files can be created using the 'new' command. This works in the same way as the write command, but you don't pass in an existing Yaml file. Currently this does not support creating multiple documents in a single yaml file. yq n path new value Creating a simple yaml file yq n b.c cat will output: b: c: cat Creating using a create script Create scripts follow the same format as the update scripts. Given a script create_instructions.yaml of: b.c: 3 b.e[0].name: Howdy Partner then yq n -s create_instructions.yaml will output: b: c: 3 e: - name: Howdy Partner You can also pipe the instructions in: cat create_instructions.yaml | yq n -s - Keys with dots When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Create"},{"location":"create/#creating-a-simple-yaml-file","text":"yq n b.c cat will output: b: c: cat","title":"Creating a simple yaml file"},{"location":"create/#creating-using-a-create-script","text":"Create scripts follow the same format as the update scripts. Given a script create_instructions.yaml of: b.c: 3 b.e[0].name: Howdy Partner then yq n -s create_instructions.yaml will output: b: c: 3 e: - name: Howdy Partner You can also pipe the instructions in: cat create_instructions.yaml | yq n -s -","title":"Creating using a create script"},{"location":"create/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"create/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Keys (and values) with leading dashes"},{"location":"delete/","text":"yq d yaml_file path_to_delete To Stdout Given a sample.yaml file of: b: c: 2 apples: green then yq d sample.yaml b.c will output: b: apples: green From STDIN cat sample.yaml | yq d - b.c Deleting array elements Given a sample.yaml file of: b: c: - 1 - 2 - 3 then yq d sample.yaml 'b.c[1]' will output: b: c: - 1 - 3 Deleting nodes in-place Given a sample.yaml file of: b: c: 2 apples: green then yq d -i sample.yaml b.c will update the sample.yaml file so that the 'c' node is deleted Multiple Documents - delete from single document Given a sample.yaml file of: something: else field: leaveMe --- b: c: 2 field: deleteMe then yq w -d1 sample.yaml field will output: something: else field: leaveMe --- b: c: 2 Multiple Documents - delete from all documents Given a sample.yaml file of: something: else field: deleteMe --- b: c: 2 field: deleteMeToo then yq w -d'*' sample.yaml field will output: something: else --- b: c: 2 Note that '*' is in quotes to avoid being interpreted by your shell. Keys with dots When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Delete"},{"location":"delete/#to-stdout","text":"Given a sample.yaml file of: b: c: 2 apples: green then yq d sample.yaml b.c will output: b: apples: green","title":"To Stdout"},{"location":"delete/#from-stdin","text":"cat sample.yaml | yq d - b.c","title":"From STDIN"},{"location":"delete/#deleting-array-elements","text":"Given a sample.yaml file of: b: c: - 1 - 2 - 3 then yq d sample.yaml 'b.c[1]' will output: b: c: - 1 - 3","title":"Deleting array elements"},{"location":"delete/#deleting-nodes-in-place","text":"Given a sample.yaml file of: b: c: 2 apples: green then yq d -i sample.yaml b.c will update the sample.yaml file so that the 'c' node is deleted","title":"Deleting nodes in-place"},{"location":"delete/#multiple-documents-delete-from-single-document","text":"Given a sample.yaml file of: something: else field: leaveMe --- b: c: 2 field: deleteMe then yq w -d1 sample.yaml field will output: something: else field: leaveMe --- b: c: 2","title":"Multiple Documents - delete from single document"},{"location":"delete/#multiple-documents-delete-from-all-documents","text":"Given a sample.yaml file of: something: else field: deleteMe --- b: c: 2 field: deleteMeToo then yq w -d'*' sample.yaml field will output: something: else --- b: c: 2 Note that '*' is in quotes to avoid being interpreted by your shell.","title":"Multiple Documents - delete from all documents"},{"location":"delete/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"delete/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Keys (and values) with leading dashes"},{"location":"merge/","text":"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. yq m yaml_file path ... To Stdout Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m data1.yaml data2.yaml will output: a: simple b: [1, 2] c: test: 1 Updating files in-place Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m -i data1.yaml data2.yaml will update the data1.yaml file so that the value of 'c' is 'test: 1'. Overwrite values Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m -x data1.yaml data2.yaml will output: a: other b: [1, 2] c: test: 1 Overwrite values with arrays Given a data1.yaml file of: a: simple b: [1, 2] and data3.yaml file of: b: [3, 4] c: test: 2 other: true d: false then yq m -x data1.yaml data3.yaml will output: a: simple 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. 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: something: else --- a: simple b: cat and data3.yaml file of: b: dog then yq m -x -d1 data1.yaml data3.yaml will output: something: else --- a: simple b: dog 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: something: else --- a: simple b: cat and data3.yaml file of: b: dog then yq m -x -d'*' data1.yaml data3.yaml will output: b: dog something: else --- a: simple b: dog","title":"Merge"},{"location":"merge/#to-stdout","text":"Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m data1.yaml data2.yaml will output: a: simple b: [1, 2] c: test: 1","title":"To Stdout"},{"location":"merge/#updating-files-in-place","text":"Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m -i data1.yaml data2.yaml will update the data1.yaml file so that the value of 'c' is 'test: 1'.","title":"Updating files in-place"},{"location":"merge/#overwrite-values","text":"Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m -x data1.yaml data2.yaml will output: a: other b: [1, 2] c: test: 1","title":"Overwrite values"},{"location":"merge/#overwrite-values-with-arrays","text":"Given a data1.yaml file of: a: simple b: [1, 2] and data3.yaml file of: b: [3, 4] c: test: 2 other: true d: false then yq m -x data1.yaml data3.yaml will output: a: simple 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.","title":"Overwrite values with arrays"},{"location":"merge/#append-values-with-arrays","text":"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.","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 --- a: simple b: cat and data3.yaml file of: b: dog then yq m -x -d1 data1.yaml data3.yaml will output: something: else --- a: simple b: dog","title":"Multiple Documents - merge into single document"},{"location":"merge/#multiple-documents-merge-into-all-documents","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 --- a: simple b: cat and data3.yaml file of: b: dog then yq m -x -d'*' data1.yaml data3.yaml will output: b: dog something: else --- a: simple b: dog","title":"Multiple Documents - merge into all documents"},{"location":"prefix/","text":"Paths can be prefixed using the 'prefix' command. The complete yaml content will be nested inside the new prefix path. yq p yaml_file path To Stdout Given a data1.yaml file of: a: simple b: [1, 2] then yq p data1.yaml c will output: c: a: simple b: [1, 2] Arbitrary depth Given a data1.yaml file of: a: b: [1, 2] then yq p data1.yaml c.d will output: c: d: a: b: [1, 2] Updating files in-place Given a data1.yaml file of: a: simple b: [1, 2] then yq p -i data1.yaml c will update the data1.yaml file so that the path 'c' is prefixed to all other paths. Multiple Documents - prefix a single document Given a data1.yaml file of: something: else --- a: simple b: cat then yq p -d1 data1.yaml c will output: something: else --- c: a: simple b: cat Multiple Documents - prefix all documents Given a data1.yaml file of: something: else --- a: simple b: cat then yq p -d'*' data1.yaml c will output: c: something: else --- c: a: simple b: cat","title":"Prefix"},{"location":"prefix/#to-stdout","text":"Given a data1.yaml file of: a: simple b: [1, 2] then yq p data1.yaml c will output: c: a: simple b: [1, 2]","title":"To Stdout"},{"location":"prefix/#arbitrary-depth","text":"Given a data1.yaml file of: a: b: [1, 2] then yq p data1.yaml c.d will output: c: d: a: b: [1, 2]","title":"Arbitrary depth"},{"location":"prefix/#updating-files-in-place","text":"Given a data1.yaml file of: a: simple b: [1, 2] then yq p -i data1.yaml c will update the data1.yaml file so that the path 'c' is prefixed to all other paths.","title":"Updating files in-place"},{"location":"prefix/#multiple-documents-prefix-a-single-document","text":"Given a data1.yaml file of: something: else --- a: simple b: cat then yq p -d1 data1.yaml c will output: something: else --- c: a: simple b: cat","title":"Multiple Documents - prefix a single document"},{"location":"prefix/#multiple-documents-prefix-all-documents","text":"Given a data1.yaml file of: something: else --- a: simple b: cat then yq p -d'*' data1.yaml c will output: c: something: else --- c: a: simple b: cat","title":"Multiple Documents - prefix all documents"},{"location":"read/","text":"yq r yaml_file|json_file path This command can take a json file as input too, and will output yaml unless specified to export as json (-j) Basic Given a sample.yaml file of: b: c: 2 then yq r sample.yaml b.c will output the value of '2'. From Stdin Given a sample.yaml file of: cat sample.yaml | yq r - b.c will output the value of '2'. Splat Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples then yq r sample.yaml bob.*.cats will output - bananas - apples Multiple Documents - specify a single document Given a sample.yaml file of: something: else --- b: c: 2 then yq r -d1 sample.yaml b.c will output the value of '2'. Multiple Documents - read all documents Reading all documents will return the result as an array. This can be converted to json using the '-j' flag if desired. Given a sample.yaml file of: name: Fred age: 22 --- name: Stella age: 23 --- name: Android age: 232 then yq r -d'*' sample.yaml name will output: - Fred - Stella - Android Arrays You can give an index to access a specific element: e.g.: given a sample file of b: e: - name: fred value: 3 - name: sam value: 4 then yq r sample.yaml 'b.e[1].name' will output 'sam' Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Array Splat e.g.: given a sample file of b: e: - name: fred value: 3 - name: sam value: 4 then yq r sample.yaml 'b.e[*].name' will output: - fred - sam Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys with dots When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Read"},{"location":"read/#basic","text":"Given a sample.yaml file of: b: c: 2 then yq r sample.yaml b.c will output the value of '2'.","title":"Basic"},{"location":"read/#from-stdin","text":"Given a sample.yaml file of: cat sample.yaml | yq r - b.c will output the value of '2'.","title":"From Stdin"},{"location":"read/#splat","text":"Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples then yq r sample.yaml bob.*.cats will output - bananas - apples","title":"Splat"},{"location":"read/#multiple-documents-specify-a-single-document","text":"Given a sample.yaml file of: something: else --- b: c: 2 then yq r -d1 sample.yaml b.c will output the value of '2'.","title":"Multiple Documents - specify a single document"},{"location":"read/#multiple-documents-read-all-documents","text":"Reading all documents will return the result as an array. This can be converted to json using the '-j' flag if desired. Given a sample.yaml file of: name: Fred age: 22 --- name: Stella age: 23 --- name: Android age: 232 then yq r -d'*' sample.yaml name will output: - Fred - Stella - Android","title":"Multiple Documents - read all documents"},{"location":"read/#arrays","text":"You can give an index to access a specific element: e.g.: given a sample file of b: e: - name: fred value: 3 - name: sam value: 4 then yq r sample.yaml 'b.e[1].name' will output 'sam' Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Arrays"},{"location":"read/#array-splat","text":"e.g.: given a sample file of b: e: - name: fred value: 3 - name: sam value: 4 then yq r sample.yaml 'b.e[*].name' will output: - fred - sam Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Array Splat"},{"location":"read/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"read/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Keys (and values) with leading dashes"},{"location":"write/","text":"yq w yaml_file path new value To Stdout Given a sample.yaml file of: b: c: 2 then yq w sample.yaml b.c cat will output: b: c: cat From STDIN cat sample.yaml | yq w - b.c blah Adding new fields Any missing fields in the path will be created on the fly. Given a sample.yaml file of: b: c: 2 then yq w sample.yaml b.d[0] new thing will output: b: c: cat d: - new thing Appending value to an array field Given a sample.yaml file of: b: c: 2 d: - new thing - foo thing then yq w sample.yaml b.d[+] bar thing will output: b: c: cat d: - new thing - foo thing - bar thing Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Multiple Documents - update a single document Given a sample.yaml file of: something: else --- b: c: 2 then yq w -d1 sample.yaml b.c 5 will output: something: else --- b: c: 5 Multiple Documents - update all documents Given a sample.yaml file of: something: else --- b: c: 2 then yq w -d'*' sample.yaml b.c 5 will output: something: else b: c: 5 --- b: c: 5 Note that '*' is in quotes to avoid being interpreted by your shell. Updating files in-place Given a sample.yaml file of: b: c: 2 then yq w -i sample.yaml b.c cat will update the sample.yaml file so that the value of 'c' is cat. Updating multiple values with a script Given a sample.yaml file of: b: c: 2 e: - name: Billy Bob and a script update_instructions.yaml of: b.c: 3 b.e[0].name: Howdy Partner then yq w -s update_instructions.yaml sample.yaml will output: b: c: 3 e: - name: Howdy Partner And, of course, you can pipe the instructions in using '-': cat update_instructions.yaml | yq w -s - sample.yaml Values starting with a hyphen (or dash) The flag terminator needs to be used to stop the app from attempting to parse the subsequent arguments as flags: yq w -- my.path -3 will output my: path: -3 Keys with dots When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Write/Update"},{"location":"write/#to-stdout","text":"Given a sample.yaml file of: b: c: 2 then yq w sample.yaml b.c cat will output: b: c: cat","title":"To Stdout"},{"location":"write/#from-stdin","text":"cat sample.yaml | yq w - b.c blah","title":"From STDIN"},{"location":"write/#adding-new-fields","text":"Any missing fields in the path will be created on the fly. Given a sample.yaml file of: b: c: 2 then yq w sample.yaml b.d[0] new thing will output: b: c: cat d: - new thing","title":"Adding new fields"},{"location":"write/#appending-value-to-an-array-field","text":"Given a sample.yaml file of: b: c: 2 d: - new thing - foo thing then yq w sample.yaml b.d[+] bar thing will output: b: c: cat d: - new thing - foo thing - bar thing Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Appending value to an array field"},{"location":"write/#multiple-documents-update-a-single-document","text":"Given a sample.yaml file of: something: else --- b: c: 2 then yq w -d1 sample.yaml b.c 5 will output: something: else --- b: c: 5","title":"Multiple Documents - update a single document"},{"location":"write/#multiple-documents-update-all-documents","text":"Given a sample.yaml file of: something: else --- b: c: 2 then yq w -d'*' sample.yaml b.c 5 will output: something: else b: c: 5 --- b: c: 5 Note that '*' is in quotes to avoid being interpreted by your shell.","title":"Multiple Documents - update all documents"},{"location":"write/#updating-files-in-place","text":"Given a sample.yaml file of: b: c: 2 then yq w -i sample.yaml b.c cat will update the sample.yaml file so that the value of 'c' is cat.","title":"Updating files in-place"},{"location":"write/#updating-multiple-values-with-a-script","text":"Given a sample.yaml file of: b: c: 2 e: - name: Billy Bob and a script update_instructions.yaml of: b.c: 3 b.e[0].name: Howdy Partner then yq w -s update_instructions.yaml sample.yaml will output: b: c: 3 e: - name: Howdy Partner And, of course, you can pipe the instructions in using '-': cat update_instructions.yaml | yq w -s - sample.yaml","title":"Updating multiple values with a script"},{"location":"write/#values-starting-with-a-hyphen-or-dash","text":"The flag terminator needs to be used to stop the app from attempting to parse the subsequent arguments as flags: yq w -- my.path -3 will output my: path: -3","title":"Values starting with a hyphen (or dash)"},{"location":"write/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"write/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Keys (and values) with leading dashes"},{"location":"snippets/niche/","text":"Keys with dots When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in --key: --value","title":"Niche"},{"location":"snippets/niche/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"snippets/niche/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in --key: --value","title":"Keys (and values) with leading dashes"},{"location":"snippets/works_with_json/","text":"This command can take a json file as input too, and will output yaml unless specified to export as json (-j)","title":"Works with json"}]}
-=======
-{"config":{"lang":["en"],"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"yq \u00b6 yq is a lightweight and portable command-line YAML processor The aim of the project is to be the jq or sed of yaml files. Install \u00b6 On MacOS: brew install yq On Ubuntu and other Linux distros supporting snap packages: snap install yq On Ubuntu 16.04 or higher from Debian package: sudo add-apt-repository ppa:rmescandon/yq sudo apt update sudo apt install yq -y or, Download latest binary or alternatively: go get gopkg.in/mikefarah/yq.v2 View on GitHub","title":"Install"},{"location":"#yq","text":"yq is a lightweight and portable command-line YAML processor The aim of the project is to be the jq or sed of yaml files.","title":"yq"},{"location":"#install","text":"On MacOS: brew install yq On Ubuntu and other Linux distros supporting snap packages: snap install yq On Ubuntu 16.04 or higher from Debian package: sudo add-apt-repository ppa:rmescandon/yq sudo apt update sudo apt install yq -y or, Download latest binary or alternatively: go get gopkg.in/mikefarah/yq.v2 View on GitHub","title":"Install"},{"location":"convert/","text":"Yaml to Json \u00b6 To convert output to json, use the --tojson (or -j) flag. This can only be used with the read command. Given a sample.yaml file of: b: c: 2 then yq r -j sample.yaml b.c will output {\"b\":{\"c\":2}} Json to Yaml \u00b6 To read in json, just pass in a json file instead of yaml, it will just work :) e.g given a json file {\"a\":\"Easy! as one two three\",\"b\":{\"c\":2,\"d\":[3,4]}} then yq r sample.json will output a: Easy! as one two three b: c: 2 d: - 3 - 4","title":"Convert"},{"location":"convert/#yaml-to-json","text":"To convert output to json, use the --tojson (or -j) flag. This can only be used with the read command. Given a sample.yaml file of: b: c: 2 then yq r -j sample.yaml b.c will output {\"b\":{\"c\":2}}","title":"Yaml to Json"},{"location":"convert/#json-to-yaml","text":"To read in json, just pass in a json file instead of yaml, it will just work :) e.g given a json file {\"a\":\"Easy! as one two three\",\"b\":{\"c\":2,\"d\":[3,4]}} then yq r sample.json will output a: Easy! as one two three b: c: 2 d: - 3 - 4","title":"Json to Yaml"},{"location":"create/","text":"Yaml files can be created using the 'new' command. This works in the same way as the write command, but you don't pass in an existing Yaml file. Currently this does not support creating multiple documents in a single yaml file. yq n Creating a simple yaml file \u00b6 yq n b.c cat will output: b: c: cat Creating using a create script \u00b6 Create scripts follow the same format as the update scripts. Given a script create_instructions.yaml of: b.c: 3 b.e[0].name: Howdy Partner then yq n -s create_instructions.yaml will output: b: c: 3 e: - name: Howdy Partner You can also pipe the instructions in: cat create_instructions.yaml | yq n -s - Keys with dots \u00b6 When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes \u00b6 If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Create"},{"location":"create/#creating-a-simple-yaml-file","text":"yq n b.c cat will output: b: c: cat","title":"Creating a simple yaml file"},{"location":"create/#creating-using-a-create-script","text":"Create scripts follow the same format as the update scripts. Given a script create_instructions.yaml of: b.c: 3 b.e[0].name: Howdy Partner then yq n -s create_instructions.yaml will output: b: c: 3 e: - name: Howdy Partner You can also pipe the instructions in: cat create_instructions.yaml | yq n -s -","title":"Creating using a create script"},{"location":"create/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"create/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Keys (and values) with leading dashes"},{"location":"delete/","text":"yq d To Stdout \u00b6 Given a sample.yaml file of: b: c: 2 apples: green then yq d sample.yaml b.c will output: b: apples: green From STDIN \u00b6 cat sample.yaml | yq d - b.c Deleting array elements \u00b6 Given a sample.yaml file of: b: c: - 1 - 2 - 3 then yq d sample.yaml 'b.c[1]' will output: b: c: - 1 - 3 Deleting nodes in-place \u00b6 Given a sample.yaml file of: b: c: 2 apples: green then yq d -i sample.yaml b.c will update the sample.yaml file so that the 'c' node is deleted Splat \u00b6 Given a sample.yaml file of: --- bob: item1: cats: bananas dogs: woof item2: cats: apples dogs: woof2 thing: cats: oranges dogs: woof3 then yq d sample.yaml bob.*.cats will output: --- bob: item1: dogs: woof item2: dogs: woof2 thing: dogs: woof3 Prefix Splat \u00b6 Given a sample.yaml file of: --- bob: item1: cats: bananas dogs: woof item2: cats: apples dogs: woof2 thing: cats: oranges dogs: woof3 then yq d sample.yaml bob.item*.cats will output: --- bob: item1: dogs: woof item2: dogs: woof2 thing: cats: oranges dogs: woof3 Array Splat \u00b6 Given a sample.yaml file of: --- bob: - cats: bananas dogs: woof - cats: apples dogs: woof2 - cats: oranges dogs: woof3 then yq d sample.yaml bob.[*].cats will output: --- bob: - dogs: woof - dogs: woof2 - dogs: woof3 Multiple Documents - delete from single document \u00b6 Given a sample.yaml file of: something: else field: leaveMe --- b: c: 2 field: deleteMe then yq w -d1 sample.yaml field will output: something: else field: leaveMe --- b: c: 2 Multiple Documents - delete from all documents \u00b6 Given a sample.yaml file of: something: else field: deleteMe --- b: c: 2 field: deleteMeToo then yq w -d'*' sample.yaml field will output: something: else --- b: c: 2 Note that '*' is in quotes to avoid being interpreted by your shell. Keys with dots \u00b6 When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes \u00b6 If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Delete"},{"location":"delete/#to-stdout","text":"Given a sample.yaml file of: b: c: 2 apples: green then yq d sample.yaml b.c will output: b: apples: green","title":"To Stdout"},{"location":"delete/#from-stdin","text":"cat sample.yaml | yq d - b.c","title":"From STDIN"},{"location":"delete/#deleting-array-elements","text":"Given a sample.yaml file of: b: c: - 1 - 2 - 3 then yq d sample.yaml 'b.c[1]' will output: b: c: - 1 - 3","title":"Deleting array elements"},{"location":"delete/#deleting-nodes-in-place","text":"Given a sample.yaml file of: b: c: 2 apples: green then yq d -i sample.yaml b.c will update the sample.yaml file so that the 'c' node is deleted","title":"Deleting nodes in-place"},{"location":"delete/#splat","text":"Given a sample.yaml file of: --- bob: item1: cats: bananas dogs: woof item2: cats: apples dogs: woof2 thing: cats: oranges dogs: woof3 then yq d sample.yaml bob.*.cats will output: --- bob: item1: dogs: woof item2: dogs: woof2 thing: dogs: woof3","title":"Splat"},{"location":"delete/#prefix-splat","text":"Given a sample.yaml file of: --- bob: item1: cats: bananas dogs: woof item2: cats: apples dogs: woof2 thing: cats: oranges dogs: woof3 then yq d sample.yaml bob.item*.cats will output: --- bob: item1: dogs: woof item2: dogs: woof2 thing: cats: oranges dogs: woof3","title":"Prefix Splat"},{"location":"delete/#array-splat","text":"Given a sample.yaml file of: --- bob: - cats: bananas dogs: woof - cats: apples dogs: woof2 - cats: oranges dogs: woof3 then yq d sample.yaml bob.[*].cats will output: --- bob: - dogs: woof - dogs: woof2 - dogs: woof3","title":"Array Splat"},{"location":"delete/#multiple-documents-delete-from-single-document","text":"Given a sample.yaml file of: something: else field: leaveMe --- b: c: 2 field: deleteMe then yq w -d1 sample.yaml field will output: something: else field: leaveMe --- b: c: 2","title":"Multiple Documents - delete from single document"},{"location":"delete/#multiple-documents-delete-from-all-documents","text":"Given a sample.yaml file of: something: else field: deleteMe --- b: c: 2 field: deleteMeToo then yq w -d'*' sample.yaml field will output: something: else --- b: c: 2 Note that '*' is in quotes to avoid being interpreted by your shell.","title":"Multiple Documents - delete from all documents"},{"location":"delete/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"delete/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Keys (and values) with leading dashes"},{"location":"merge/","text":"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. yq m ... To Stdout \u00b6 Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m data1.yaml data2.yaml will output: a: simple b: [1, 2] c: test: 1 Updating files in-place \u00b6 Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m -i data1.yaml data2.yaml will update the data1.yaml file so that the value of 'c' is 'test: 1'. Overwrite values \u00b6 Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m -x data1.yaml data2.yaml will output: a: other b: [1, 2] c: test: 1 Overwrite values with arrays \u00b6 Given a data1.yaml file of: a: simple b: [1, 2] and data3.yaml file of: b: [3, 4] c: test: 2 other: true d: false then yq m -x data1.yaml data3.yaml will output: a: simple 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. Append values with arrays \u00b6 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 \u00b6 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 --- a: simple b: cat and data3.yaml file of: b: dog then yq m -x -d1 data1.yaml data3.yaml will output: something: else --- a: simple b: dog Multiple Documents - merge into all documents \u00b6 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 --- a: simple b: cat and data3.yaml file of: b: dog then yq m -x -d'*' data1.yaml data3.yaml will output: b: dog something: else --- a: simple b: dog","title":"Merge"},{"location":"merge/#to-stdout","text":"Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m data1.yaml data2.yaml will output: a: simple b: [1, 2] c: test: 1","title":"To Stdout"},{"location":"merge/#updating-files-in-place","text":"Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m -i data1.yaml data2.yaml will update the data1.yaml file so that the value of 'c' is 'test: 1'.","title":"Updating files in-place"},{"location":"merge/#overwrite-values","text":"Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m -x data1.yaml data2.yaml will output: a: other b: [1, 2] c: test: 1","title":"Overwrite values"},{"location":"merge/#overwrite-values-with-arrays","text":"Given a data1.yaml file of: a: simple b: [1, 2] and data3.yaml file of: b: [3, 4] c: test: 2 other: true d: false then yq m -x data1.yaml data3.yaml will output: a: simple 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.","title":"Overwrite values with arrays"},{"location":"merge/#append-values-with-arrays","text":"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.","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 --- a: simple b: cat and data3.yaml file of: b: dog then yq m -x -d1 data1.yaml data3.yaml will output: something: else --- a: simple b: dog","title":"Multiple Documents - merge into single document"},{"location":"merge/#multiple-documents-merge-into-all-documents","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 --- a: simple b: cat and data3.yaml file of: b: dog then yq m -x -d'*' data1.yaml data3.yaml will output: b: dog something: else --- a: simple b: dog","title":"Multiple Documents - merge into all documents"},{"location":"prefix/","text":"Paths can be prefixed using the 'prefix' command. The complete yaml content will be nested inside the new prefix path. yq p To Stdout \u00b6 Given a data1.yaml file of: a: simple b: [1, 2] then yq p data1.yaml c will output: c: a: simple b: [1, 2] Arbitrary depth \u00b6 Given a data1.yaml file of: a: b: [1, 2] then yq p data1.yaml c.d will output: c: d: a: b: [1, 2] Updating files in-place \u00b6 Given a data1.yaml file of: a: simple b: [1, 2] then yq p -i data1.yaml c will update the data1.yaml file so that the path 'c' is prefixed to all other paths. Multiple Documents - prefix a single document \u00b6 Given a data1.yaml file of: something: else --- a: simple b: cat then yq p -d1 data1.yaml c will output: something: else --- c: a: simple b: cat Multiple Documents - prefix all documents \u00b6 Given a data1.yaml file of: something: else --- a: simple b: cat then yq p -d'*' data1.yaml c will output: c: something: else --- c: a: simple b: cat","title":"Prefix"},{"location":"prefix/#to-stdout","text":"Given a data1.yaml file of: a: simple b: [1, 2] then yq p data1.yaml c will output: c: a: simple b: [1, 2]","title":"To Stdout"},{"location":"prefix/#arbitrary-depth","text":"Given a data1.yaml file of: a: b: [1, 2] then yq p data1.yaml c.d will output: c: d: a: b: [1, 2]","title":"Arbitrary depth"},{"location":"prefix/#updating-files-in-place","text":"Given a data1.yaml file of: a: simple b: [1, 2] then yq p -i data1.yaml c will update the data1.yaml file so that the path 'c' is prefixed to all other paths.","title":"Updating files in-place"},{"location":"prefix/#multiple-documents-prefix-a-single-document","text":"Given a data1.yaml file of: something: else --- a: simple b: cat then yq p -d1 data1.yaml c will output: something: else --- c: a: simple b: cat","title":"Multiple Documents - prefix a single document"},{"location":"prefix/#multiple-documents-prefix-all-documents","text":"Given a data1.yaml file of: something: else --- a: simple b: cat then yq p -d'*' data1.yaml c will output: c: something: else --- c: a: simple b: cat","title":"Multiple Documents - prefix all documents"},{"location":"read/","text":"yq r This command can take a json file as input too, and will output yaml unless specified to export as json (-j) Basic \u00b6 Given a sample.yaml file of: b: c: 2 then yq r sample.yaml b.c will output the value of '2'. From Stdin \u00b6 Given a sample.yaml file of: cat sample.yaml | yq r - b.c will output the value of '2'. Splat \u00b6 Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples thing: cats: oranges then yq r sample.yaml bob.*.cats will output - bananas - apples - oranges Prefix Splat \u00b6 Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples thing: cats: oranges then yq r sample.yaml bob.item*.cats will output - bananas - apples Multiple Documents - specify a single document \u00b6 Given a sample.yaml file of: something: else --- b: c: 2 then yq r -d1 sample.yaml b.c will output the value of '2'. Multiple Documents - read all documents \u00b6 Reading all documents will return the result as an array. This can be converted to json using the '-j' flag if desired. Given a sample.yaml file of: name: Fred age: 22 --- name: Stella age: 23 --- name: Android age: 232 then yq r -d'*' sample.yaml name will output: - Fred - Stella - Android Arrays \u00b6 You can give an index to access a specific element: e.g.: given a sample file of b: e: - name: fred value: 3 - name: sam value: 4 then yq r sample.yaml 'b.e[1].name' will output 'sam' Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Array Splat \u00b6 e.g.: given a sample file of b: e: - name: fred value: 3 - name: sam value: 4 then yq r sample.yaml 'b.e[*].name' will output: - fred - sam Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys with dots \u00b6 When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes \u00b6 If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Read"},{"location":"read/#basic","text":"Given a sample.yaml file of: b: c: 2 then yq r sample.yaml b.c will output the value of '2'.","title":"Basic"},{"location":"read/#from-stdin","text":"Given a sample.yaml file of: cat sample.yaml | yq r - b.c will output the value of '2'.","title":"From Stdin"},{"location":"read/#splat","text":"Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples thing: cats: oranges then yq r sample.yaml bob.*.cats will output - bananas - apples - oranges","title":"Splat"},{"location":"read/#prefix-splat","text":"Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples thing: cats: oranges then yq r sample.yaml bob.item*.cats will output - bananas - apples","title":"Prefix Splat"},{"location":"read/#multiple-documents-specify-a-single-document","text":"Given a sample.yaml file of: something: else --- b: c: 2 then yq r -d1 sample.yaml b.c will output the value of '2'.","title":"Multiple Documents - specify a single document"},{"location":"read/#multiple-documents-read-all-documents","text":"Reading all documents will return the result as an array. This can be converted to json using the '-j' flag if desired. Given a sample.yaml file of: name: Fred age: 22 --- name: Stella age: 23 --- name: Android age: 232 then yq r -d'*' sample.yaml name will output: - Fred - Stella - Android","title":"Multiple Documents - read all documents"},{"location":"read/#arrays","text":"You can give an index to access a specific element: e.g.: given a sample file of b: e: - name: fred value: 3 - name: sam value: 4 then yq r sample.yaml 'b.e[1].name' will output 'sam' Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Arrays"},{"location":"read/#array-splat","text":"e.g.: given a sample file of b: e: - name: fred value: 3 - name: sam value: 4 then yq r sample.yaml 'b.e[*].name' will output: - fred - sam Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Array Splat"},{"location":"read/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"read/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Keys (and values) with leading dashes"},{"location":"write/","text":"yq w To Stdout \u00b6 Given a sample.yaml file of: b: c: 2 then yq w sample.yaml b.c cat will output: b: c: cat From STDIN \u00b6 cat sample.yaml | yq w - b.c blah Adding new fields \u00b6 Any missing fields in the path will be created on the fly. Given a sample.yaml file of: b: c: 2 then yq w sample.yaml b.d[0] \"new thing\" will output: b: c: cat d: - new thing Splat \u00b6 Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples thing: cats: oranges then yq w sample.yaml bob.*.cats meow will output: --- bob: item1: cats: meow item2: cats: meow thing: cats: meow Prefix Splat \u00b6 Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples thing: cats: oranges then yq w sample.yaml bob.item*.cats meow will output: --- bob: item1: cats: meow item2: cats: meow thing: cats: oranges Array Splat \u00b6 Given a sample.yaml file of: --- bob: - cats: bananas - cats: apples - cats: oranges then yq w sample.yaml bob[*].cats meow will output: --- bob: - cats: meow - cats: meow - cats: meow Appending value to an array field \u00b6 Given a sample.yaml file of: b: c: 2 d: - new thing - foo thing then yq w sample.yaml \"b.d[+]\" \"bar thing\" will output: b: c: cat d: - new thing - foo thing - bar thing Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Multiple Documents - update a single document \u00b6 Given a sample.yaml file of: something: else --- b: c: 2 then yq w -d1 sample.yaml b.c 5 will output: something: else --- b: c: 5 Multiple Documents - update all documents \u00b6 Given a sample.yaml file of: something: else --- b: c: 2 then yq w -d'*' sample.yaml b.c 5 will output: something: else b: c: 5 --- b: c: 5 Note that '*' is in quotes to avoid being interpreted by your shell. Updating files in-place \u00b6 Given a sample.yaml file of: b: c: 2 then yq w -i sample.yaml b.c cat will update the sample.yaml file so that the value of 'c' is cat. Updating multiple values with a script \u00b6 Given a sample.yaml file of: b: c: 2 e: - name: Billy Bob and a script update_instructions.yaml of: b.c: 3 b.e[0].name: Howdy Partner then yq w -s update_instructions.yaml sample.yaml will output: b: c: 3 e: - name: Howdy Partner And, of course, you can pipe the instructions in using '-': cat update_instructions.yaml | yq w -s - sample.yaml Values starting with a hyphen (or dash) \u00b6 The flag terminator needs to be used to stop the app from attempting to parse the subsequent arguments as flags: yq w -- my.path -3 will output my: path: -3 Keys with dots \u00b6 When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes \u00b6 If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Write/Update"},{"location":"write/#to-stdout","text":"Given a sample.yaml file of: b: c: 2 then yq w sample.yaml b.c cat will output: b: c: cat","title":"To Stdout"},{"location":"write/#from-stdin","text":"cat sample.yaml | yq w - b.c blah","title":"From STDIN"},{"location":"write/#adding-new-fields","text":"Any missing fields in the path will be created on the fly. Given a sample.yaml file of: b: c: 2 then yq w sample.yaml b.d[0] \"new thing\" will output: b: c: cat d: - new thing","title":"Adding new fields"},{"location":"write/#splat","text":"Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples thing: cats: oranges then yq w sample.yaml bob.*.cats meow will output: --- bob: item1: cats: meow item2: cats: meow thing: cats: meow","title":"Splat"},{"location":"write/#prefix-splat","text":"Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples thing: cats: oranges then yq w sample.yaml bob.item*.cats meow will output: --- bob: item1: cats: meow item2: cats: meow thing: cats: oranges","title":"Prefix Splat"},{"location":"write/#array-splat","text":"Given a sample.yaml file of: --- bob: - cats: bananas - cats: apples - cats: oranges then yq w sample.yaml bob[*].cats meow will output: --- bob: - cats: meow - cats: meow - cats: meow","title":"Array Splat"},{"location":"write/#appending-value-to-an-array-field","text":"Given a sample.yaml file of: b: c: 2 d: - new thing - foo thing then yq w sample.yaml \"b.d[+]\" \"bar thing\" will output: b: c: cat d: - new thing - foo thing - bar thing Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Appending value to an array field"},{"location":"write/#multiple-documents-update-a-single-document","text":"Given a sample.yaml file of: something: else --- b: c: 2 then yq w -d1 sample.yaml b.c 5 will output: something: else --- b: c: 5","title":"Multiple Documents - update a single document"},{"location":"write/#multiple-documents-update-all-documents","text":"Given a sample.yaml file of: something: else --- b: c: 2 then yq w -d'*' sample.yaml b.c 5 will output: something: else b: c: 5 --- b: c: 5 Note that '*' is in quotes to avoid being interpreted by your shell.","title":"Multiple Documents - update all documents"},{"location":"write/#updating-files-in-place","text":"Given a sample.yaml file of: b: c: 2 then yq w -i sample.yaml b.c cat will update the sample.yaml file so that the value of 'c' is cat.","title":"Updating files in-place"},{"location":"write/#updating-multiple-values-with-a-script","text":"Given a sample.yaml file of: b: c: 2 e: - name: Billy Bob and a script update_instructions.yaml of: b.c: 3 b.e[0].name: Howdy Partner then yq w -s update_instructions.yaml sample.yaml will output: b: c: 3 e: - name: Howdy Partner And, of course, you can pipe the instructions in using '-': cat update_instructions.yaml | yq w -s - sample.yaml","title":"Updating multiple values with a script"},{"location":"write/#values-starting-with-a-hyphen-or-dash","text":"The flag terminator needs to be used to stop the app from attempting to parse the subsequent arguments as flags: yq w -- my.path -3 will output my: path: -3","title":"Values starting with a hyphen (or dash)"},{"location":"write/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"write/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Keys (and values) with leading dashes"},{"location":"snippets/niche/","text":"Keys with dots \u00b6 When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes \u00b6 If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in --key: --value","title":"Niche"},{"location":"snippets/niche/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"snippets/niche/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in --key: --value","title":"Keys (and values) with leading dashes"},{"location":"snippets/works_with_json/","text":"This command can take a json file as input too, and will output yaml unless specified to export as json (-j)","title":"Works with json"}]}
->>>>>>> Updated instructions
+{"config":{"lang":["en"],"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"yq \u00b6 yq is a lightweight and portable command-line YAML processor The aim of the project is to be the jq or sed of yaml files. Install \u00b6 On MacOS: brew install yq On Ubuntu and other Linux distros supporting snap packages: snap install yq On Ubuntu 16.04 or higher from Debian package: sudo add-apt-repository ppa:rmescandon/yq sudo apt update sudo apt install yq -y or, Download latest binary or alternatively: go get gopkg.in/mikefarah/yq.v2 View on GitHub","title":"Install"},{"location":"#yq","text":"yq is a lightweight and portable command-line YAML processor The aim of the project is to be the jq or sed of yaml files.","title":"yq"},{"location":"#install","text":"On MacOS: brew install yq On Ubuntu and other Linux distros supporting snap packages: snap install yq On Ubuntu 16.04 or higher from Debian package: sudo add-apt-repository ppa:rmescandon/yq sudo apt update sudo apt install yq -y or, Download latest binary or alternatively: go get gopkg.in/mikefarah/yq.v2 View on GitHub","title":"Install"},{"location":"convert/","text":"Yaml to Json \u00b6 To convert output to json, use the --tojson (or -j) flag. This can only be used with the read command. Given a sample.yaml file of: b: c: 2 then yq r -j sample.yaml b.c will output {\"b\":{\"c\":2}} Json to Yaml \u00b6 To read in json, just pass in a json file instead of yaml, it will just work :) e.g given a json file {\"a\":\"Easy! as one two three\",\"b\":{\"c\":2,\"d\":[3,4]}} then yq r sample.json will output a: Easy! as one two three b: c: 2 d: - 3 - 4","title":"Convert"},{"location":"convert/#yaml-to-json","text":"To convert output to json, use the --tojson (or -j) flag. This can only be used with the read command. Given a sample.yaml file of: b: c: 2 then yq r -j sample.yaml b.c will output {\"b\":{\"c\":2}}","title":"Yaml to Json"},{"location":"convert/#json-to-yaml","text":"To read in json, just pass in a json file instead of yaml, it will just work :) e.g given a json file {\"a\":\"Easy! as one two three\",\"b\":{\"c\":2,\"d\":[3,4]}} then yq r sample.json will output a: Easy! as one two three b: c: 2 d: - 3 - 4","title":"Json to Yaml"},{"location":"create/","text":"Yaml files can be created using the 'new' command. This works in the same way as the write command, but you don't pass in an existing Yaml file. Currently this does not support creating multiple documents in a single yaml file. yq n Creating a simple yaml file \u00b6 yq n b.c cat will output: b: c: cat Creating using a create script \u00b6 Create scripts follow the same format as the update scripts. Given a script create_instructions.yaml of: b.c: 3 b.e[+].name: Howdy Partner then yq n -s create_instructions.yaml will output: b: c: 3 e: - name: Howdy Partner You can also pipe the instructions in: cat create_instructions.yaml | yq n -s - Keys with dots \u00b6 When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes \u00b6 If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Create"},{"location":"create/#creating-a-simple-yaml-file","text":"yq n b.c cat will output: b: c: cat","title":"Creating a simple yaml file"},{"location":"create/#creating-using-a-create-script","text":"Create scripts follow the same format as the update scripts. Given a script create_instructions.yaml of: b.c: 3 b.e[+].name: Howdy Partner then yq n -s create_instructions.yaml will output: b: c: 3 e: - name: Howdy Partner You can also pipe the instructions in: cat create_instructions.yaml | yq n -s -","title":"Creating using a create script"},{"location":"create/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"create/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Keys (and values) with leading dashes"},{"location":"delete/","text":"yq d To Stdout \u00b6 Given a sample.yaml file of: b: c: 2 apples: green then yq d sample.yaml b.c will output: b: apples: green From STDIN \u00b6 cat sample.yaml | yq d - b.c Deleting array elements \u00b6 Given a sample.yaml file of: b: c: - 1 - 2 - 3 then yq d sample.yaml 'b.c[1]' will output: b: c: - 1 - 3 Deleting nodes in-place \u00b6 Given a sample.yaml file of: b: c: 2 apples: green then yq d -i sample.yaml b.c will update the sample.yaml file so that the 'c' node is deleted Splat \u00b6 Given a sample.yaml file of: --- bob: item1: cats: bananas dogs: woof item2: cats: apples dogs: woof2 thing: cats: oranges dogs: woof3 then yq d sample.yaml bob.*.cats will output: --- bob: item1: dogs: woof item2: dogs: woof2 thing: dogs: woof3 Prefix Splat \u00b6 Given a sample.yaml file of: --- bob: item1: cats: bananas dogs: woof item2: cats: apples dogs: woof2 thing: cats: oranges dogs: woof3 then yq d sample.yaml bob.item*.cats will output: --- bob: item1: dogs: woof item2: dogs: woof2 thing: cats: oranges dogs: woof3 Array Splat \u00b6 Given a sample.yaml file of: --- bob: - cats: bananas dogs: woof - cats: apples dogs: woof2 - cats: oranges dogs: woof3 then yq d sample.yaml bob.[*].cats will output: --- bob: - dogs: woof - dogs: woof2 - dogs: woof3 Multiple Documents - delete from single document \u00b6 Given a sample.yaml file of: something: else field: leaveMe --- b: c: 2 field: deleteMe then yq w -d1 sample.yaml field will output: something: else field: leaveMe --- b: c: 2 Multiple Documents - delete from all documents \u00b6 Given a sample.yaml file of: something: else field: deleteMe --- b: c: 2 field: deleteMeToo then yq w -d'*' sample.yaml field will output: something: else --- b: c: 2 Note that '*' is in quotes to avoid being interpreted by your shell. Keys with dots \u00b6 When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes \u00b6 If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Delete"},{"location":"delete/#to-stdout","text":"Given a sample.yaml file of: b: c: 2 apples: green then yq d sample.yaml b.c will output: b: apples: green","title":"To Stdout"},{"location":"delete/#from-stdin","text":"cat sample.yaml | yq d - b.c","title":"From STDIN"},{"location":"delete/#deleting-array-elements","text":"Given a sample.yaml file of: b: c: - 1 - 2 - 3 then yq d sample.yaml 'b.c[1]' will output: b: c: - 1 - 3","title":"Deleting array elements"},{"location":"delete/#deleting-nodes-in-place","text":"Given a sample.yaml file of: b: c: 2 apples: green then yq d -i sample.yaml b.c will update the sample.yaml file so that the 'c' node is deleted","title":"Deleting nodes in-place"},{"location":"delete/#splat","text":"Given a sample.yaml file of: --- bob: item1: cats: bananas dogs: woof item2: cats: apples dogs: woof2 thing: cats: oranges dogs: woof3 then yq d sample.yaml bob.*.cats will output: --- bob: item1: dogs: woof item2: dogs: woof2 thing: dogs: woof3","title":"Splat"},{"location":"delete/#prefix-splat","text":"Given a sample.yaml file of: --- bob: item1: cats: bananas dogs: woof item2: cats: apples dogs: woof2 thing: cats: oranges dogs: woof3 then yq d sample.yaml bob.item*.cats will output: --- bob: item1: dogs: woof item2: dogs: woof2 thing: cats: oranges dogs: woof3","title":"Prefix Splat"},{"location":"delete/#array-splat","text":"Given a sample.yaml file of: --- bob: - cats: bananas dogs: woof - cats: apples dogs: woof2 - cats: oranges dogs: woof3 then yq d sample.yaml bob.[*].cats will output: --- bob: - dogs: woof - dogs: woof2 - dogs: woof3","title":"Array Splat"},{"location":"delete/#multiple-documents-delete-from-single-document","text":"Given a sample.yaml file of: something: else field: leaveMe --- b: c: 2 field: deleteMe then yq w -d1 sample.yaml field will output: something: else field: leaveMe --- b: c: 2","title":"Multiple Documents - delete from single document"},{"location":"delete/#multiple-documents-delete-from-all-documents","text":"Given a sample.yaml file of: something: else field: deleteMe --- b: c: 2 field: deleteMeToo then yq w -d'*' sample.yaml field will output: something: else --- b: c: 2 Note that '*' is in quotes to avoid being interpreted by your shell.","title":"Multiple Documents - delete from all documents"},{"location":"delete/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"delete/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Keys (and values) with leading dashes"},{"location":"merge/","text":"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. yq m ... To Stdout \u00b6 Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m data1.yaml data2.yaml will output: a: simple b: [1, 2] c: test: 1 Updating files in-place \u00b6 Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m -i data1.yaml data2.yaml will update the data1.yaml file so that the value of 'c' is 'test: 1'. Overwrite values \u00b6 Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m -x data1.yaml data2.yaml will output: a: other b: [1, 2] c: test: 1 Overwrite values with arrays \u00b6 Given a data1.yaml file of: a: simple b: [1, 2] and data3.yaml file of: b: [3, 4] c: test: 2 other: true d: false then yq m -x data1.yaml data3.yaml will output: a: simple 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. Append values with arrays \u00b6 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 \u00b6 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 --- a: simple b: cat and data3.yaml file of: b: dog then yq m -x -d1 data1.yaml data3.yaml will output: something: else --- a: simple b: dog Multiple Documents - merge into all documents \u00b6 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 --- a: simple b: cat and data3.yaml file of: b: dog then yq m -x -d'*' data1.yaml data3.yaml will output: b: dog something: else --- a: simple b: dog","title":"Merge"},{"location":"merge/#to-stdout","text":"Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m data1.yaml data2.yaml will output: a: simple b: [1, 2] c: test: 1","title":"To Stdout"},{"location":"merge/#updating-files-in-place","text":"Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m -i data1.yaml data2.yaml will update the data1.yaml file so that the value of 'c' is 'test: 1'.","title":"Updating files in-place"},{"location":"merge/#overwrite-values","text":"Given a data1.yaml file of: a: simple b: [1, 2] and data2.yaml file of: a: other c: test: 1 then yq m -x data1.yaml data2.yaml will output: a: other b: [1, 2] c: test: 1","title":"Overwrite values"},{"location":"merge/#overwrite-values-with-arrays","text":"Given a data1.yaml file of: a: simple b: [1, 2] and data3.yaml file of: b: [3, 4] c: test: 2 other: true d: false then yq m -x data1.yaml data3.yaml will output: a: simple 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.","title":"Overwrite values with arrays"},{"location":"merge/#append-values-with-arrays","text":"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.","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 --- a: simple b: cat and data3.yaml file of: b: dog then yq m -x -d1 data1.yaml data3.yaml will output: something: else --- a: simple b: dog","title":"Multiple Documents - merge into single document"},{"location":"merge/#multiple-documents-merge-into-all-documents","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 --- a: simple b: cat and data3.yaml file of: b: dog then yq m -x -d'*' data1.yaml data3.yaml will output: b: dog something: else --- a: simple b: dog","title":"Multiple Documents - merge into all documents"},{"location":"prefix/","text":"Paths can be prefixed using the 'prefix' command. The complete yaml content will be nested inside the new prefix path. yq p To Stdout \u00b6 Given a data1.yaml file of: a: simple b: [1, 2] then yq p data1.yaml c will output: c: a: simple b: [1, 2] Arbitrary depth \u00b6 Given a data1.yaml file of: a: b: [1, 2] then yq p data1.yaml c.d will output: c: d: a: b: [1, 2] Updating files in-place \u00b6 Given a data1.yaml file of: a: simple b: [1, 2] then yq p -i data1.yaml c will update the data1.yaml file so that the path 'c' is prefixed to all other paths. Multiple Documents - prefix a single document \u00b6 Given a data1.yaml file of: something: else --- a: simple b: cat then yq p -d1 data1.yaml c will output: something: else --- c: a: simple b: cat Multiple Documents - prefix all documents \u00b6 Given a data1.yaml file of: something: else --- a: simple b: cat then yq p -d'*' data1.yaml c will output: c: something: else --- c: a: simple b: cat","title":"Prefix"},{"location":"prefix/#to-stdout","text":"Given a data1.yaml file of: a: simple b: [1, 2] then yq p data1.yaml c will output: c: a: simple b: [1, 2]","title":"To Stdout"},{"location":"prefix/#arbitrary-depth","text":"Given a data1.yaml file of: a: b: [1, 2] then yq p data1.yaml c.d will output: c: d: a: b: [1, 2]","title":"Arbitrary depth"},{"location":"prefix/#updating-files-in-place","text":"Given a data1.yaml file of: a: simple b: [1, 2] then yq p -i data1.yaml c will update the data1.yaml file so that the path 'c' is prefixed to all other paths.","title":"Updating files in-place"},{"location":"prefix/#multiple-documents-prefix-a-single-document","text":"Given a data1.yaml file of: something: else --- a: simple b: cat then yq p -d1 data1.yaml c will output: something: else --- c: a: simple b: cat","title":"Multiple Documents - prefix a single document"},{"location":"prefix/#multiple-documents-prefix-all-documents","text":"Given a data1.yaml file of: something: else --- a: simple b: cat then yq p -d'*' data1.yaml c will output: c: something: else --- c: a: simple b: cat","title":"Multiple Documents - prefix all documents"},{"location":"read/","text":"yq r This command can take a json file as input too, and will output yaml unless specified to export as json (-j) Basic \u00b6 Given a sample.yaml file of: b: c: 2 then yq r sample.yaml b.c will output the value of '2'. From Stdin \u00b6 Given a sample.yaml file of: cat sample.yaml | yq r - b.c will output the value of '2'. Splat \u00b6 Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples thing: cats: oranges then yq r sample.yaml bob.*.cats will output - bananas - apples - oranges Prefix Splat \u00b6 Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples thing: cats: oranges then yq r sample.yaml bob.item*.cats will output - bananas - apples Multiple Documents - specify a single document \u00b6 Given a sample.yaml file of: something: else --- b: c: 2 then yq r -d1 sample.yaml b.c will output the value of '2'. Multiple Documents - read all documents \u00b6 Reading all documents will return the result as an array. This can be converted to json using the '-j' flag if desired. Given a sample.yaml file of: name: Fred age: 22 --- name: Stella age: 23 --- name: Android age: 232 then yq r -d'*' sample.yaml name will output: - Fred - Stella - Android Arrays \u00b6 You can give an index to access a specific element: e.g.: given a sample file of b: e: - name: fred value: 3 - name: sam value: 4 then yq r sample.yaml 'b.e[1].name' will output 'sam' Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Array Splat \u00b6 e.g.: given a sample file of b: e: - name: fred value: 3 - name: sam value: 4 then yq r sample.yaml 'b.e[*].name' will output: - fred - sam Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys with dots \u00b6 When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes \u00b6 If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Read"},{"location":"read/#basic","text":"Given a sample.yaml file of: b: c: 2 then yq r sample.yaml b.c will output the value of '2'.","title":"Basic"},{"location":"read/#from-stdin","text":"Given a sample.yaml file of: cat sample.yaml | yq r - b.c will output the value of '2'.","title":"From Stdin"},{"location":"read/#splat","text":"Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples thing: cats: oranges then yq r sample.yaml bob.*.cats will output - bananas - apples - oranges","title":"Splat"},{"location":"read/#prefix-splat","text":"Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples thing: cats: oranges then yq r sample.yaml bob.item*.cats will output - bananas - apples","title":"Prefix Splat"},{"location":"read/#multiple-documents-specify-a-single-document","text":"Given a sample.yaml file of: something: else --- b: c: 2 then yq r -d1 sample.yaml b.c will output the value of '2'.","title":"Multiple Documents - specify a single document"},{"location":"read/#multiple-documents-read-all-documents","text":"Reading all documents will return the result as an array. This can be converted to json using the '-j' flag if desired. Given a sample.yaml file of: name: Fred age: 22 --- name: Stella age: 23 --- name: Android age: 232 then yq r -d'*' sample.yaml name will output: - Fred - Stella - Android","title":"Multiple Documents - read all documents"},{"location":"read/#arrays","text":"You can give an index to access a specific element: e.g.: given a sample file of b: e: - name: fred value: 3 - name: sam value: 4 then yq r sample.yaml 'b.e[1].name' will output 'sam' Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Arrays"},{"location":"read/#array-splat","text":"e.g.: given a sample file of b: e: - name: fred value: 3 - name: sam value: 4 then yq r sample.yaml 'b.e[*].name' will output: - fred - sam Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Array Splat"},{"location":"read/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"read/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Keys (and values) with leading dashes"},{"location":"write/","text":"yq w To Stdout \u00b6 Given a sample.yaml file of: b: c: 2 then yq w sample.yaml b.c cat will output: b: c: cat From STDIN \u00b6 cat sample.yaml | yq w - b.c blah Adding new fields \u00b6 Any missing fields in the path will be created on the fly. Given a sample.yaml file of: b: c: 2 then yq w sample.yaml b.d[+] \"new thing\" will output: b: c: cat d: - new thing Splat \u00b6 Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples thing: cats: oranges then yq w sample.yaml bob.*.cats meow will output: --- bob: item1: cats: meow item2: cats: meow thing: cats: meow Prefix Splat \u00b6 Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples thing: cats: oranges then yq w sample.yaml bob.item*.cats meow will output: --- bob: item1: cats: meow item2: cats: meow thing: cats: oranges Array Splat \u00b6 Given a sample.yaml file of: --- bob: - cats: bananas - cats: apples - cats: oranges then yq w sample.yaml bob[*].cats meow will output: --- bob: - cats: meow - cats: meow - cats: meow Appending value to an array field \u00b6 Given a sample.yaml file of: b: c: 2 d: - new thing - foo thing then yq w sample.yaml \"b.d[+]\" \"bar thing\" will output: b: c: cat d: - new thing - foo thing - bar thing Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Multiple Documents - update a single document \u00b6 Given a sample.yaml file of: something: else --- b: c: 2 then yq w -d1 sample.yaml b.c 5 will output: something: else --- b: c: 5 Multiple Documents - update all documents \u00b6 Given a sample.yaml file of: something: else --- b: c: 2 then yq w -d'*' sample.yaml b.c 5 will output: something: else b: c: 5 --- b: c: 5 Note that '*' is in quotes to avoid being interpreted by your shell. Updating files in-place \u00b6 Given a sample.yaml file of: b: c: 2 then yq w -i sample.yaml b.c cat will update the sample.yaml file so that the value of 'c' is cat. Updating multiple values with a script \u00b6 Given a sample.yaml file of: b: c: 2 e: - name: Billy Bob and a script update_instructions.yaml of: b.c: 3 b.e[+].name: Howdy Partner then yq w -s update_instructions.yaml sample.yaml will output: b: c: 3 e: - name: Howdy Partner And, of course, you can pipe the instructions in using '-': cat update_instructions.yaml | yq w -s - sample.yaml Values starting with a hyphen (or dash) \u00b6 The flag terminator needs to be used to stop the app from attempting to parse the subsequent arguments as flags: yq w -- my.path -3 will output my: path: -3 Keys with dots \u00b6 When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes \u00b6 If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Write/Update"},{"location":"write/#to-stdout","text":"Given a sample.yaml file of: b: c: 2 then yq w sample.yaml b.c cat will output: b: c: cat","title":"To Stdout"},{"location":"write/#from-stdin","text":"cat sample.yaml | yq w - b.c blah","title":"From STDIN"},{"location":"write/#adding-new-fields","text":"Any missing fields in the path will be created on the fly. Given a sample.yaml file of: b: c: 2 then yq w sample.yaml b.d[+] \"new thing\" will output: b: c: cat d: - new thing","title":"Adding new fields"},{"location":"write/#splat","text":"Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples thing: cats: oranges then yq w sample.yaml bob.*.cats meow will output: --- bob: item1: cats: meow item2: cats: meow thing: cats: meow","title":"Splat"},{"location":"write/#prefix-splat","text":"Given a sample.yaml file of: --- bob: item1: cats: bananas item2: cats: apples thing: cats: oranges then yq w sample.yaml bob.item*.cats meow will output: --- bob: item1: cats: meow item2: cats: meow thing: cats: oranges","title":"Prefix Splat"},{"location":"write/#array-splat","text":"Given a sample.yaml file of: --- bob: - cats: bananas - cats: apples - cats: oranges then yq w sample.yaml bob[*].cats meow will output: --- bob: - cats: meow - cats: meow - cats: meow","title":"Array Splat"},{"location":"write/#appending-value-to-an-array-field","text":"Given a sample.yaml file of: b: c: 2 d: - new thing - foo thing then yq w sample.yaml \"b.d[+]\" \"bar thing\" will output: b: c: cat d: - new thing - foo thing - bar thing Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Appending value to an array field"},{"location":"write/#multiple-documents-update-a-single-document","text":"Given a sample.yaml file of: something: else --- b: c: 2 then yq w -d1 sample.yaml b.c 5 will output: something: else --- b: c: 5","title":"Multiple Documents - update a single document"},{"location":"write/#multiple-documents-update-all-documents","text":"Given a sample.yaml file of: something: else --- b: c: 2 then yq w -d'*' sample.yaml b.c 5 will output: something: else b: c: 5 --- b: c: 5 Note that '*' is in quotes to avoid being interpreted by your shell.","title":"Multiple Documents - update all documents"},{"location":"write/#updating-files-in-place","text":"Given a sample.yaml file of: b: c: 2 then yq w -i sample.yaml b.c cat will update the sample.yaml file so that the value of 'c' is cat.","title":"Updating files in-place"},{"location":"write/#updating-multiple-values-with-a-script","text":"Given a sample.yaml file of: b: c: 2 e: - name: Billy Bob and a script update_instructions.yaml of: b.c: 3 b.e[+].name: Howdy Partner then yq w -s update_instructions.yaml sample.yaml will output: b: c: 3 e: - name: Howdy Partner And, of course, you can pipe the instructions in using '-': cat update_instructions.yaml | yq w -s - sample.yaml","title":"Updating multiple values with a script"},{"location":"write/#values-starting-with-a-hyphen-or-dash","text":"The flag terminator needs to be used to stop the app from attempting to parse the subsequent arguments as flags: yq w -- my.path -3 will output my: path: -3","title":"Values starting with a hyphen (or dash)"},{"location":"write/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"write/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in ` --key: --value","title":"Keys (and values) with leading dashes"},{"location":"snippets/niche/","text":"Keys with dots \u00b6 When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell. Keys (and values) with leading dashes \u00b6 If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in --key: --value","title":"Niche"},{"location":"snippets/niche/#keys-with-dots","text":"When specifying a key that has a dot use key lookup indicator. b: foo.bar: 7 yaml r sample.yaml 'b[foo.bar]' yaml w sample.yaml 'b[foo.bar]' 9 Any valid yaml key can be specified as part of a key lookup. Note that the path is in quotes to avoid the square brackets being interpreted by your shell.","title":"Keys with dots"},{"location":"snippets/niche/#keys-and-values-with-leading-dashes","text":"If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error). To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so: yq n -t -- --key --value Will result in --key: --value","title":"Keys (and values) with leading dashes"},{"location":"snippets/works_with_json/","text":"This command can take a json file as input too, and will output yaml unless specified to export as json (-j)","title":"Works with json"}]}
\ No newline at end of file
diff --git a/docs/sitemap.xml b/docs/sitemap.xml
index 52d1935b..ec7d85c7 100644
--- a/docs/sitemap.xml
+++ b/docs/sitemap.xml
@@ -2,42 +2,42 @@
None
- 2019-05-14
+ 2019-05-16
daily
None
- 2019-05-14
+ 2019-05-16
daily
None
- 2019-05-14
+ 2019-05-16
daily
None
- 2019-05-14
+ 2019-05-16
daily
None
- 2019-05-14
+ 2019-05-16
daily
None
- 2019-05-14
+ 2019-05-16
daily
None
- 2019-05-14
+ 2019-05-16
daily
None
- 2019-05-14
+ 2019-05-16
daily
\ No newline at end of file
diff --git a/docs/sitemap.xml.gz b/docs/sitemap.xml.gz
index c15bfb479ed8e64079f7a7755052592f559127b3..4e4ff0f686910e7bc6a89a76e507f69946c15eb7 100644
GIT binary patch
delta 38
ucmX@fc#@G_zMF$%#oId**=3p3q$aAButYyUsy1<+GRIyA>91dz85jTsR1J9m
delta 38
ucmX@fc#@G_zMF$XSZ+T#YBh15GKb)zYR0e33=9DKg$%p^
diff --git a/docs/write/index.html b/docs/write/index.html
index c3907db1..d094d64e 100644
--- a/docs/write/index.html
+++ b/docs/write/index.html
@@ -611,7 +611,7 @@
then
-yq w sample.yaml b.d[0] "new thing"
+yq w sample.yaml b.d[+] "new thing"
will output:
@@ -781,7 +781,7 @@ b:
and a script update_instructions.yaml of:
b.c: 3
-b.e[0].name: Howdy Partner
+b.e[+].name: Howdy Partner
then
diff --git a/mkdocs/create.md b/mkdocs/create.md
index 569960f4..302c01e1 100644
--- a/mkdocs/create.md
+++ b/mkdocs/create.md
@@ -20,7 +20,7 @@ Create scripts follow the same format as the update scripts.
Given a script create_instructions.yaml of:
```yaml
b.c: 3
-b.e[0].name: Howdy Partner
+b.e[+].name: Howdy Partner
```
then
diff --git a/mkdocs/write.md b/mkdocs/write.md
index f80aad69..0959081c 100644
--- a/mkdocs/write.md
+++ b/mkdocs/write.md
@@ -33,7 +33,7 @@ b:
```
then
```bash
-yq w sample.yaml b.d[0] "new thing"
+yq w sample.yaml b.d[+] "new thing"
```
will output:
```yaml
@@ -214,7 +214,7 @@ b:
and a script update_instructions.yaml of:
```yaml
b.c: 3
-b.e[0].name: Howdy Partner
+b.e[+].name: Howdy Partner
```
then
From be532bf2fe543f0b25385a6bf7887336c9f58cf6 Mon Sep 17 00:00:00 2001
From: Eduardo Minguez Perez
Date: Fri, 7 Jun 2019 14:16:24 +0200
Subject: [PATCH 40/54] Added '-rm' docker flag to remove the containers
Also, added a handy alias just in case.
---
README.md | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index e56c9cb3..26af3ff2 100644
--- a/README.md
+++ b/README.md
@@ -51,13 +51,19 @@ go get gopkg.in/mikefarah/yq.v2
Oneshot use:
```bash
-docker run -v ${PWD}:/workdir mikefarah/yq yq [flags] FILE...
+docker run -rm -v ${PWD}:/workdir mikefarah/yq yq [flags] FILE...
```
Run commands interactively:
```bash
-docker run -it -v ${PWD}:/workdir mikefarah/yq sh
+docker run -rm -it -v ${PWD}:/workdir mikefarah/yq sh
+```
+
+It can be useful to have a bash alias to avoid typing the whole docker command:
+
+```bash
+alias yq="docker run -rm -v ${PWD}:/workdir mikefarah/yq yq"
```
## Features
From f8553162ca7494ea58c12f2dcdf8ef31ad58342f Mon Sep 17 00:00:00 2001
From: Arnaud Deprez
Date: Tue, 2 Jul 2019 12:17:35 +0000
Subject: [PATCH 41/54] doc: use '--rm' instead of '-rm' for docker command
---
README.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index 26af3ff2..e6a5d13d 100644
--- a/README.md
+++ b/README.md
@@ -51,19 +51,19 @@ go get gopkg.in/mikefarah/yq.v2
Oneshot use:
```bash
-docker run -rm -v ${PWD}:/workdir mikefarah/yq yq [flags] FILE...
+docker run --rm -v ${PWD}:/workdir mikefarah/yq yq [flags] FILE...
```
Run commands interactively:
```bash
-docker run -rm -it -v ${PWD}:/workdir mikefarah/yq sh
+docker run --rm -it -v ${PWD}:/workdir mikefarah/yq sh
```
It can be useful to have a bash alias to avoid typing the whole docker command:
```bash
-alias yq="docker run -rm -v ${PWD}:/workdir mikefarah/yq yq"
+alias yq="docker run --rm -v ${PWD}:/workdir mikefarah/yq yq"
```
## Features
From 7b54a44fcfe87a9a9e7cf0c778beb939df8af26d Mon Sep 17 00:00:00 2001
From: Mike Farah
Date: Tue, 23 Jul 2019 09:57:58 +1000
Subject: [PATCH 42/54] Fixed readme for bash docker alias to bash function,
thanks @dead10ck
---
README.md | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index e6a5d13d..5846d029 100644
--- a/README.md
+++ b/README.md
@@ -60,10 +60,12 @@ Run commands interactively:
docker run --rm -it -v ${PWD}:/workdir mikefarah/yq sh
```
-It can be useful to have a bash alias to avoid typing the whole docker command:
+It can be useful to have a bash function to avoid typing the whole docker command:
```bash
-alias yq="docker run --rm -v ${PWD}:/workdir mikefarah/yq yq"
+yq() {
+ docker run --rm -i -v ${PWD}:/workdir mikefarah/yq yq $@
+}
```
## Features
From 665d9079fa42b58a9c29c2fb2dbf0aa64c880e75 Mon Sep 17 00:00:00 2001
From: Mike Farah
Date: Tue, 23 Jul 2019 10:07:59 +1000
Subject: [PATCH 43/54] Added goreport to readme
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 5846d029..40461bcc 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# yq
-[](https://travis-ci.org/mikefarah/yq)  
+[](https://travis-ci.org/mikefarah/yq)   
a lightweight and portable command-line YAML processor
From bc4bab9380c666abc03ec1f42d7294a5bf8ff1b8 Mon Sep 17 00:00:00 2001
From: Azimjon Ilkhomov <31452507+ajilk@users.noreply.github.com>
Date: Fri, 2 Aug 2019 00:20:57 -0400
Subject: [PATCH 44/54] Fix typo
---
scripts/acceptance.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/acceptance.sh b/scripts/acceptance.sh
index 9f15a091..309d588b 100755
--- a/scripts/acceptance.sh
+++ b/scripts/acceptance.sh
@@ -6,7 +6,7 @@ set -e
X=$(./yq w ./examples/sample.yaml b.c 3 | ./yq r - b.c)
if [[ $X != 3 ]]; then
- echo "Failed acceptance test: expected 2 but was $X"
+ echo "Failed acceptance test: expected 3 but was $X"
exit 1
fi
echo "acceptance tests passed"
From a9e871ee003a61f369d32a0033942b18a6ebf0fc Mon Sep 17 00:00:00 2001
From: Aleksandr Sergin
Date: Fri, 23 Aug 2019 18:20:05 +0300
Subject: [PATCH 45/54] add Move func to avoid 'invalid cross-device link'
---
yq.go | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/yq.go b/yq.go
index f005a83e..a16af4b2 100644
--- a/yq.go
+++ b/yq.go
@@ -37,6 +37,35 @@ func main() {
}
}
+/*
+ GoLang: os.Rename() give error "invalid cross-device link" for Docker container with Volumes.
+ MoveFile(source, destination) will work moving file between folders
+*/
+
+func MoveFile(sourcePath, destPath string) error {
+ inputFile, err := os.Open(sourcePath)
+ if err != nil {
+ return fmt.Errorf("Couldn't open source file: %s", err)
+ }
+ outputFile, err := os.Create(destPath)
+ if err != nil {
+ inputFile.Close()
+ return fmt.Errorf("Couldn't open dest file: %s", err)
+ }
+ defer outputFile.Close()
+ _, err = io.Copy(outputFile, inputFile)
+ inputFile.Close()
+ if err != nil {
+ return fmt.Errorf("Writing to output file failed: %s", err)
+ }
+ // The copy was successful, so now delete the original file
+ err = os.Remove(sourcePath)
+ if err != nil {
+ return fmt.Errorf("Failed removing original file: %s", err)
+ }
+ return nil
+}
+
func newCommandCLI() *cobra.Command {
yaml.DefaultMapType = reflect.TypeOf(yaml.MapSlice{})
var rootCmd = &cobra.Command{
@@ -625,7 +654,7 @@ func marshalContext(context interface{}) (string, error) {
}
func safelyRenameFile(from string, to string) {
- if renameError := os.Rename(from, to); renameError != nil {
+ if renameError := MoveFile(from, to); renameError != nil {
log.Warningf("Error renaming from %v to %v, attemting to copy contents", from, to)
log.Warning(renameError.Error())
// can't do this rename when running in docker to a file targeted in a mounted volume,
From 2f70e6f27a7e2136e54ee6349921ebf2022d7451 Mon Sep 17 00:00:00 2001
From: Aleksandr Sergin
Date: Fri, 23 Aug 2019 19:03:43 +0300
Subject: [PATCH 46/54] fix linter error
---
yq.go | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/yq.go b/yq.go
index a16af4b2..2ebc8496 100644
--- a/yq.go
+++ b/yq.go
@@ -37,11 +37,8 @@ func main() {
}
}
-/*
- GoLang: os.Rename() give error "invalid cross-device link" for Docker container with Volumes.
- MoveFile(source, destination) will work moving file between folders
-*/
-
+//MoveFile - os.Rename() give error "invalid cross-device link" for Docker container with Volumes.
+//MoveFile(source, destination) will work moving file between folders
func MoveFile(sourcePath, destPath string) error {
inputFile, err := os.Open(sourcePath)
if err != nil {
From 7320b8d3c92cb13fb2db3cbb64acf8cad7c626a9 Mon Sep 17 00:00:00 2001
From: Aleksandr Sergin
Date: Fri, 23 Aug 2019 19:08:31 +0300
Subject: [PATCH 47/54] fix linter error
---
yq.go | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/yq.go b/yq.go
index 2ebc8496..2aa87c04 100644
--- a/yq.go
+++ b/yq.go
@@ -42,23 +42,23 @@ func main() {
func MoveFile(sourcePath, destPath string) error {
inputFile, err := os.Open(sourcePath)
if err != nil {
- return fmt.Errorf("Couldn't open source file: %s", err)
+ return fmt.Errorf("couldn't open source file: %s", err)
}
outputFile, err := os.Create(destPath)
if err != nil {
inputFile.Close()
- return fmt.Errorf("Couldn't open dest file: %s", err)
+ return fmt.Errorf("couldn't open dest file: %s", err)
}
defer outputFile.Close()
_, err = io.Copy(outputFile, inputFile)
inputFile.Close()
if err != nil {
- return fmt.Errorf("Writing to output file failed: %s", err)
+ return fmt.Errorf("writing to output file failed: %s", err)
}
// The copy was successful, so now delete the original file
err = os.Remove(sourcePath)
if err != nil {
- return fmt.Errorf("Failed removing original file: %s", err)
+ return fmt.Errorf("failed removing original file: %s", err)
}
return nil
}
From 5de2bea1b4c945d8d26f0cde5bb3545e9a7600d6 Mon Sep 17 00:00:00 2001
From: Aleksandr Sergin
Date: Fri, 23 Aug 2019 19:31:01 +0300
Subject: [PATCH 48/54] fix linter error
---
yq.go | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/yq.go b/yq.go
index 2aa87c04..d41d311b 100644
--- a/yq.go
+++ b/yq.go
@@ -46,12 +46,18 @@ func MoveFile(sourcePath, destPath string) error {
}
outputFile, err := os.Create(destPath)
if err != nil {
- inputFile.Close()
+ err = inputFile.Close()
+ if err != nil {
+ return fmt.Errorf("Failed close original file: %s", err)
+ }
return fmt.Errorf("couldn't open dest file: %s", err)
}
defer outputFile.Close()
_, err = io.Copy(outputFile, inputFile)
- inputFile.Close()
+ err = inputFile.Close()
+ if err != nil {
+ return fmt.Errorf("Failed close original file: %s", err)
+ }
if err != nil {
return fmt.Errorf("writing to output file failed: %s", err)
}
From 7a28531f2f85d3003319e30d2a5cc7a408c91ba6 Mon Sep 17 00:00:00 2001
From: Aleksandr Sergin
Date: Fri, 23 Aug 2019 19:44:35 +0300
Subject: [PATCH 49/54] fix linter error
---
yq.go | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/yq.go b/yq.go
index d41d311b..f75daf45 100644
--- a/yq.go
+++ b/yq.go
@@ -48,7 +48,7 @@ func MoveFile(sourcePath, destPath string) error {
if err != nil {
err = inputFile.Close()
if err != nil {
- return fmt.Errorf("Failed close original file: %s", err)
+ return fmt.Errorf("failed close original file: %s", err)
}
return fmt.Errorf("couldn't open dest file: %s", err)
}
@@ -56,7 +56,7 @@ func MoveFile(sourcePath, destPath string) error {
_, err = io.Copy(outputFile, inputFile)
err = inputFile.Close()
if err != nil {
- return fmt.Errorf("Failed close original file: %s", err)
+ return fmt.Errorf("failed close original file: %s", err)
}
if err != nil {
return fmt.Errorf("writing to output file failed: %s", err)
From a9c0ef571c7922f3b61553ff34570bd71921ba5b Mon Sep 17 00:00:00 2001
From: Aleksandr Sergin
Date: Fri, 23 Aug 2019 20:06:15 +0300
Subject: [PATCH 50/54] fix linter error
---
yq.go | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/yq.go b/yq.go
index f75daf45..95ea4e98 100644
--- a/yq.go
+++ b/yq.go
@@ -46,18 +46,12 @@ func MoveFile(sourcePath, destPath string) error {
}
outputFile, err := os.Create(destPath)
if err != nil {
- err = inputFile.Close()
- if err != nil {
- return fmt.Errorf("failed close original file: %s", err)
- }
+ defer safelyCloseFile(inputFile)
return fmt.Errorf("couldn't open dest file: %s", err)
}
- defer outputFile.Close()
+ defer safelyCloseFile(outputFile)
_, err = io.Copy(outputFile, inputFile)
- err = inputFile.Close()
- if err != nil {
- return fmt.Errorf("failed close original file: %s", err)
- }
+ defer safelyCloseFile(inputFile)
if err != nil {
return fmt.Errorf("writing to output file failed: %s", err)
}
From 5acc1e661e4987b472749f38b571e99db024e229 Mon Sep 17 00:00:00 2001
From: Aleksandr Sergin
Date: Fri, 23 Aug 2019 20:11:44 +0300
Subject: [PATCH 51/54] fix linter error
---
yq.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/yq.go b/yq.go
index 95ea4e98..e63c4959 100644
--- a/yq.go
+++ b/yq.go
@@ -40,7 +40,7 @@ func main() {
//MoveFile - os.Rename() give error "invalid cross-device link" for Docker container with Volumes.
//MoveFile(source, destination) will work moving file between folders
func MoveFile(sourcePath, destPath string) error {
- inputFile, err := os.Open(sourcePath)
+ inputFile, err := os.Open(sourcePath) // nolint gosec
if err != nil {
return fmt.Errorf("couldn't open source file: %s", err)
}
From 8f5ffe47ff9196450623132152f4b605693e5081 Mon Sep 17 00:00:00 2001
From: Aleksandr Sergin
Date: Mon, 26 Aug 2019 12:41:56 +0300
Subject: [PATCH 52/54] return to old behavior, small fix.
---
yq.go | 38 ++++++++------------------------------
1 file changed, 8 insertions(+), 30 deletions(-)
diff --git a/yq.go b/yq.go
index e63c4959..dfb5804e 100644
--- a/yq.go
+++ b/yq.go
@@ -37,32 +37,6 @@ func main() {
}
}
-//MoveFile - os.Rename() give error "invalid cross-device link" for Docker container with Volumes.
-//MoveFile(source, destination) will work moving file between folders
-func MoveFile(sourcePath, destPath string) error {
- inputFile, err := os.Open(sourcePath) // nolint gosec
- if err != nil {
- return fmt.Errorf("couldn't open source file: %s", err)
- }
- outputFile, err := os.Create(destPath)
- if err != nil {
- defer safelyCloseFile(inputFile)
- return fmt.Errorf("couldn't open dest file: %s", err)
- }
- defer safelyCloseFile(outputFile)
- _, err = io.Copy(outputFile, inputFile)
- defer safelyCloseFile(inputFile)
- if err != nil {
- return fmt.Errorf("writing to output file failed: %s", err)
- }
- // The copy was successful, so now delete the original file
- err = os.Remove(sourcePath)
- if err != nil {
- return fmt.Errorf("failed removing original file: %s", err)
- }
- return nil
-}
-
func newCommandCLI() *cobra.Command {
yaml.DefaultMapType = reflect.TypeOf(yaml.MapSlice{})
var rootCmd = &cobra.Command{
@@ -651,14 +625,18 @@ func marshalContext(context interface{}) (string, error) {
}
func safelyRenameFile(from string, to string) {
- if renameError := MoveFile(from, to); renameError != nil {
- log.Warningf("Error renaming from %v to %v, attemting to copy contents", from, to)
- log.Warning(renameError.Error())
+ if renameError := os.Rename(from, to); renameError != nil {
+ log.Debugf("Error renaming from %v to %v, attemting to copy contents", from, to)
+ log.Debug(renameError.Error())
// can't do this rename when running in docker to a file targeted in a mounted volume,
// so gracefully degrade to copying the entire contents.
if copyError := copyFileContents(from, to); copyError != nil {
log.Errorf("Failed copying from %v to %v", from, to)
- log.Errorf(copyError.Error())
+ log.Error(copyError.Error())
+ removeErr := os.Remove(from)
+ if removeErr != nil {
+ log.Errorf("failed removing original file: %s", from)
+ }
}
}
}
From e0d8cd6bf60ec71e281dbb563b0f695af000e784 Mon Sep 17 00:00:00 2001
From: Aleksandr Sergin
Date: Mon, 26 Aug 2019 16:08:19 +0300
Subject: [PATCH 53/54] yq small fix
---
yq.go | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/yq.go b/yq.go
index dfb5804e..458ca6ea 100644
--- a/yq.go
+++ b/yq.go
@@ -633,11 +633,11 @@ func safelyRenameFile(from string, to string) {
if copyError := copyFileContents(from, to); copyError != nil {
log.Errorf("Failed copying from %v to %v", from, to)
log.Error(copyError.Error())
- removeErr := os.Remove(from)
- if removeErr != nil {
- log.Errorf("failed removing original file: %s", from)
- }
}
+ removeErr := os.Remove(from)
+ if removeErr != nil {
+ log.Errorf("failed removing original file: %s", from)
+ }
}
}
From fe5842e5f9ce3350e3253113a74a235aa8d9f519 Mon Sep 17 00:00:00 2001
From: Mike Farah
Date: Tue, 27 Aug 2019 09:21:39 +1000
Subject: [PATCH 54/54] Fix: Only remove original file if copying was
successful
---
yq.go | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/yq.go b/yq.go
index 458ca6ea..549cfbc2 100644
--- a/yq.go
+++ b/yq.go
@@ -633,11 +633,12 @@ func safelyRenameFile(from string, to string) {
if copyError := copyFileContents(from, to); copyError != nil {
log.Errorf("Failed copying from %v to %v", from, to)
log.Error(copyError.Error())
+ } else {
+ removeErr := os.Remove(from)
+ if removeErr != nil {
+ log.Errorf("failed removing original file: %s", from)
+ }
}
- removeErr := os.Remove(from)
- if removeErr != nil {
- log.Errorf("failed removing original file: %s", from)
- }
}
}