Ask Your Question
4

Can you use YQ to cut a list and save the modified version to a YAML file?

asked 2023-05-16 00:41:03 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-05-16 00:57:02 +0000

nofretete gravatar image

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".

edit flag offensive delete link more

Your Answer

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

Add Answer


Question Tools

Stats

Asked: 2023-05-16 00:41:03 +0000

Seen: 8 times

Last updated: May 16 '23