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".
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-05-16 00:41:03 +0000
Seen: 9 times
Last updated: May 16 '23
Why is awk -i inplace not functioning properly when used within a script?
How can pipelines be used to sort data based on their counts?
How can a customized trigger be established for RabbitMQ queues in Zabbix?
Can you extract certain values located between columns in two separate csv files using Grep?
What is the Grep command that can be used to extract a section of the last line?
How can a decimal output be used in an if-else statement with an awk condition?
How can multiple patterns be counted in a file using AWK?
How can values in one file be replaced with values from another file in an efficient manner?