2025-03-14 21:59:59 -06:00
|
|
|
# yq
|
|
|
|
|
|
2025-07-24 22:27:13 -06:00
|
|
|
> A lightweight and portable YAML processor.
|
2025-03-14 21:59:59 -06:00
|
|
|
> More information: <https://mikefarah.gitbook.io/yq/>.
|
|
|
|
|
|
|
|
|
|
- Output a YAML file, in pretty-print format (v4+):
|
|
|
|
|
|
|
|
|
|
`yq eval {{path/to/file.yaml}}`
|
|
|
|
|
|
|
|
|
|
- Output a YAML file, in pretty-print format (v3):
|
|
|
|
|
|
2025-04-03 20:36:56 -06:00
|
|
|
`yq read {{path/to/file.yaml}} {{[-C|--colors]}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Output the first element in a YAML file that contains only an array (v4+):
|
|
|
|
|
|
|
|
|
|
`yq eval '.[0]' {{path/to/file.yaml}}`
|
|
|
|
|
|
|
|
|
|
- Output the first element in a YAML file that contains only an array (v3):
|
|
|
|
|
|
|
|
|
|
`yq read {{path/to/file.yaml}} '[0]'`
|
|
|
|
|
|
|
|
|
|
- Set (or overwrite) a key to a value in a file (v4+):
|
|
|
|
|
|
2025-04-03 20:36:56 -06:00
|
|
|
`yq eval '.{{key}} = "{{value}}"' {{[-i|--inplace]}} {{path/to/file.yaml}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Set (or overwrite) a key to a value in a file (v3):
|
|
|
|
|
|
2025-04-03 20:36:56 -06:00
|
|
|
`yq write {{[-i|--inplace]}} {{path/to/file.yaml}} '{{key}}' '{{value}}'`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Merge two files and print to `stdout` (v4+):
|
|
|
|
|
|
|
|
|
|
`yq eval-all 'select(filename == "{{path/to/file1.yaml}}") * select(filename == "{{path/to/file2.yaml}}")' {{path/to/file1.yaml}} {{path/to/file2.yaml}}`
|
|
|
|
|
|
|
|
|
|
- Merge two files and print to `stdout` (v3):
|
|
|
|
|
|
2025-04-03 20:36:56 -06:00
|
|
|
`yq merge {{path/to/file1.yaml}} {{path/to/file2.yaml}} {{[-C|--colors]}}`
|