yq/pkg/yqlib/doc/operators/headers/Main.md

64 lines
1.8 KiB
Markdown
Raw Normal View History

2021-10-14 22:51:42 +00:00
# NAME
2021-10-14 23:39:33 +00:00
*yq* is a portable command-line YAML processor
2021-10-14 22:51:42 +00:00
# SYNOPSIS
2021-10-14 23:39:33 +00:00
yq [eval/eval-all] [expression] files..
2022-01-27 06:21:10 +00:00
eval/e - (default) Apply the expression to each document in each yaml file in sequence
2021-10-14 23:39:33 +00:00
eval-all/ea - Loads all yaml documents of all yaml files and runs expression once
# DESCRIPTION
2021-10-14 22:59:08 +00:00
2021-10-14 23:39:33 +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.
This documentation is also available at https://mikefarah.gitbook.io/yq/
2021-10-14 22:51:42 +00:00
# QUICK GUIDE
## Read a value:
```bash
2022-01-27 06:21:10 +00:00
yq '.a.b[0].c' file.yaml
2021-10-14 22:51:42 +00:00
```
## Pipe from STDIN:
```bash
2022-01-27 06:21:10 +00:00
cat file.yaml | yq '.a.b[0].c'
2021-10-14 22:51:42 +00:00
```
2023-09-18 23:52:36 +00:00
## Update a yaml file, in place
2021-10-14 22:51:42 +00:00
```bash
2022-01-27 06:21:10 +00:00
yq -i '.a.b[0].c = "cool"' file.yaml
2021-10-14 22:51:42 +00:00
```
## Update using environment variables
```bash
2022-01-27 06:21:10 +00:00
NAME=mike yq -i '.a.b[0].c = strenv(NAME)' file.yaml
2021-10-14 22:51:42 +00:00
```
## Merge multiple files
```
yq ea '. as $item ireduce ({}; . * $item )' path/to/*.yml
```
2022-01-27 06:21:10 +00:00
Note the use of `ea` to evaluate all files at once (instead of in sequence.)
2021-10-14 22:51:42 +00:00
## Multiple updates to a yaml file
```bash
2022-01-27 06:21:10 +00:00
yq -i '
2021-10-14 22:51:42 +00:00
.a.b[0].c = "cool" |
.x.y.z = "foobar" |
.person.name = strenv(NAME)
' file.yaml
```
See the [documentation](https://mikefarah.gitbook.io/yq/) for more.
# 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: https://mikefarah.gitbook.io/yq/usage/tips-and-tricks#quotes-in-windows-powershell
2021-10-14 23:39:33 +00:00
# BUGS / ISSUES / FEATURE REQUESTS
2021-11-03 02:54:09 +00:00
Please visit the GitHub page https://github.com/mikefarah/yq/.