Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

No, YQ is a tool used for querying and modifying YAML files, but it does not have the capability to directly save the modified version to a YAML file. However, you can use a combination of YQ and another tool such as sed or awk to achieve this. Here is an example command:

yq e '.list | map(select(.name != "item2"))' input.yaml | sed 's/^- /\n- /g' > output.yaml

This command uses YQ to filter out the item with name "item2" from the "list" key in the input YAML file. The output is then piped to sed to format the output YAML file properly with new line and bullet points. Finally, the output is redirected to a new YAML file named "output.yaml".