I would like to do this from the command line I have tried sed and echo It does get added but without the correct indentation and yml format is very syntax sensitive. This guide covers installation on linux distributions like ubuntu, fedora, and opensuse, and usage examples such as reading, modifying, and merging yaml data Ideal for developers and system administrators, `yq` maintains original file formatting and provides a powerful alternative to manual editing. In the bash shell, we need tools to deal with yaml content from the command line or script
In this tutorial, we’re going to learn about the yq utility The yq command is usually not a part of standard linux distribution, so we need to install it manually Then, let’s go through the command’s basics I have a config.yaml file which i want to edit or make changes to using a bash script So i got a command using grep and sed which gives me the desired changes , but the problem is that when i apply sed it gets applied to whole file including the section i want to edit. If you'd like to overwrite the original file, i recommend writing to a temporary file first and only if that succeeds, use os.rename to move that file in place of the original one.
You should always use a parser to do that kind of updating, using a shell script (calling sed or awk) that doesn't know about yaml internals is guaranteed to break at some point.
OPEN