pkg/yqlib/doc/operators/headers/Main.md
yq is a portable command-line data file processor
yq [eval/eval-all] [expression] files..
eval/e - (default) Apply the expression to each document in each yaml file in sequence
eval-all/ea - Loads all yaml documents of all yaml files and runs expression once
a lightweight and portable command-line data file processor. yq uses jq like syntax but works with yaml, json, xml, csv, properties and TOML files. 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/
yq '.a.b[0].c' file.yaml
cat file.yaml | yq '.a.b[0].c'
yq -i '.a.b[0].c = "cool"' file.yaml
NAME=mike yq -i '.a.b[0].c = strenv(NAME)' file.yaml
yq ea '. as $item ireduce ({}; . * $item )' path/to/*.yml
Note the use of ea to evaluate all files at once (instead of in sequence.)
yq -i '
.a.b[0].c = "cool" |
.x.y.z = "foobar" |
.person.name = strenv(NAME)
' file.yaml
See the documentation for more.
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)Please visit the GitHub page https://github.com/mikefarah/yq/.