1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-07-28 09:35:26 +02:00
tldr/pages/common/yq.md
Managor 23340cc6e0
common/*: reduce usage of "command-line" (part 1) (#16949)
Co-authored-by: Dylan <145150333+dmmqz@users.noreply.github.com>
Co-authored-by: Lena <126529524+acuteenvy@users.noreply.github.com>
2025-06-29 11:48:18 +03:00

36 lines
1.1 KiB
Markdown

# yq
> A lightweight and portable YAML processor.
> 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):
`yq read {{path/to/file.yaml}} {{[-C|--colors]}}`
- 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+):
`yq eval '.{{key}} = "{{value}}"' {{[-i|--inplace]}} {{path/to/file.yaml}}`
- Set (or overwrite) a key to a value in a file (v3):
`yq write {{[-i|--inplace]}} {{path/to/file.yaml}} '{{key}}' '{{value}}'`
- 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):
`yq merge {{path/to/file1.yaml}} {{path/to/file2.yaml}} {{[-C|--colors]}}`