How to add a line in sed if not match is found

BashSed

Bash Problem Overview


I am using the following sed command to replace some parameters in a config file:

sed -i 's/^option.*/option=value/g' /etc/fdm_monitor.conf

Now I have one problem. If the line does not exist, I want to add it to the bottom of the file.

I am calling this with a popen out of a C program. I tried using awk.

Bash Solutions


Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEvilmachineView Question on Stackoverflow