yq/README.md

51 lines
1.6 KiB
Markdown
Raw Normal View History

2021-10-30 03:14:39 +00:00
# yq
2021-11-03 10:51:28 +00:00
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.
2021-10-30 03:14:39 +00:00
2021-11-03 10:51:28 +00:00
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.
2021-10-30 03:14:39 +00:00
2021-11-03 10:51:28 +00:00
## Quick Usage Guide
2021-10-30 03:14:39 +00:00
2021-11-03 10:51:28 +00:00
Read a value:
2021-10-30 03:14:39 +00:00
```bash
2021-11-03 10:51:28 +00:00
yq e '.a.b[0].c' file.yaml
2021-10-30 03:14:39 +00:00
```
2021-11-03 10:51:28 +00:00
Pipe from STDIN:
2021-10-30 03:14:39 +00:00
```bash
2021-11-03 10:51:28 +00:00
cat file.yaml | yq e '.a.b[0].c' -
2021-10-30 03:14:39 +00:00
```
2021-11-03 10:51:28 +00:00
Update a yaml file, inplace
2021-10-30 03:14:39 +00:00
```bash
2021-11-03 10:51:28 +00:00
yq e -i '.a.b[0].c = "cool"' file.yaml
2021-10-30 03:14:39 +00:00
```
2021-11-03 10:51:28 +00:00
Update using environment variables
2021-10-30 03:14:39 +00:00
```bash
2021-11-03 10:51:28 +00:00
NAME=mike yq e -i '.a.b[0].c = strenv(NAME)' file.yaml
2021-10-30 03:14:39 +00:00
```
2021-11-03 10:51:28 +00:00
Merge multiple files
2021-10-30 03:14:39 +00:00
```
2021-11-03 10:51:28 +00:00
yq ea '. as $item ireduce ({}; . * $item )' path/to/*.yml
2021-10-30 03:14:39 +00:00
```
2021-11-03 10:51:28 +00:00
Multiple updates to a yaml file
2021-10-30 03:14:39 +00:00
```bash
2021-11-03 10:51:28 +00:00
yq e -i '
.a.b[0].c = "cool" |
.x.y.z = "foobar" |
.person.name = strenv(NAME)
' file.yaml
2021-10-30 03:14:39 +00:00
```
2021-11-03 10:51:28 +00:00
## Install
See the [github page](https://github.com/mikefarah/yq/#install) for the various ways you can install and use `yq`
2021-10-30 03:14:39 +00:00
2021-11-03 10:51:28 +00:00
## Known Issues / Missing Features
- `yq` attempts to preserve comment positions and whitespace as much as possible, but it does not handle all scenarios (see https://github.com/go-yaml/yaml/tree/v3 for details)
- Powershell has its own...[opinions on quoting yq](https://mikefarah.gitbook.io/yq/usage/tips-and-tricks#quotes-in-windows-powershell)
2021-10-30 03:14:39 +00:00
2021-11-03 10:51:28 +00:00
See [tips and tricks](https://mikefarah.gitbook.io/yq/usage/tips-and-tricks) for more common problems and solutions.