From eaf26894c179ae36ef72a43c6459f8d9ba20ae9b Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Wed, 23 Jul 2025 16:15:42 +1000 Subject: [PATCH] Updating readme --- README.md | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a081850d..93b4a43f 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # yq -a lightweight and portable command-line YAML processor. `yq` uses [jq](https://github.com/stedolan/jq) like syntax but works with yaml files as well as json. It doesn't yet support everything `jq` does - but it does support the most common operations and functions, and more is being added continuously. +aa lightweight and portable command-line YAML, JSON, INI and XML processor. `yq` uses [jq](https://github.com/stedolan/jq) like syntax but works with yaml files as well as json, xml, ini, properties, csv and tsv. It doesn't yet support everything `jq` does - but it does support the most common operations and functions, and more is being added continuously. -yq is written in go - so you can download a dependency free binary for your platform and you are good to go! If you prefer there are a variety of package managers that can be used as well as docker, all listed below. +yq is written in go - so you can download a dependency free binary for your platform and you are good to go! If you prefer there are a variety of package managers that can be used as well as Docker and Podman, all listed below. ## Quick Usage Guide @@ -13,10 +13,10 @@ yq '.a.b[0].c' file.yaml Pipe from STDIN: ```bash -cat file.yaml | yq '.a.b[0].c' +yq '.a.b[0].c' < file.yaml ``` -Update a yaml file, inplace +Update a yaml file, in place ```bash yq -i '.a.b[0].c = "cool"' file.yaml ``` @@ -27,7 +27,13 @@ NAME=mike yq -i '.a.b[0].c = strenv(NAME)' file.yaml ``` Merge multiple files -``` +```bash +# merge two files +yq -n 'load("file1.yaml") * load("file2.yaml")' + +# merge using globs: +# note the use of `ea` to evaluate all the files at once +# instead of in sequence yq ea '. as $item ireduce ({}; . * $item )' path/to/*.yml ``` @@ -40,6 +46,18 @@ yq -i ' ' file.yaml ``` +Find and update an item in an array: +```bash +yq '(.[] | select(.name == "foo") | .address) = "12 cat st"' +``` + +Convert JSON to YAML +```bash +yq -Poy sample.json +``` + +See [recipes](https://mikefarah.gitbook.io/yq/recipes) for more examples and the [documentation](https://mikefarah.gitbook.io/yq/) for more information. + Take a look at the discussions for [common questions](https://github.com/mikefarah/yq/discussions/categories/q-a), and [cool ideas](https://github.com/mikefarah/yq/discussions/categories/show-and-tell) ## Install