Reputation: 87
I am trying to write a script to auto install openvpn. The last thing I have to do is insert the configuration file to auto start. I have tried using sed to simply search for a line before where I'm looking to insert my new but it doesn't seem to be working, I think due to the quotation marks in the command.
Do what I have is:
#AUTOSTART="all"
#AUTOSTART="none"
#AUTOSTART="home office”
Then I run my sed command:
sed -i 's/home office"/home office"\n AUTORUN="Netherlands"/' openvpn
I've looked around and tried escaping my double quote marks to see if that was the issue, but that didn't work out.
My end goal is to have:
#AUTOSTART="all"
#AUTOSTART="none"
#AUTOSTART="home office”
AUTOSTART=“Netherlands”
Upvotes: 1
Views: 117
Reputation: 530843
You don't need to substitute anything. sed
can add text after the desired line.
sed -i '/home office/a\
AUTOSTART="Netherlands"\
' openvpn
Upvotes: 3
Reputation: 41987
You can do:
$ sed 's/"home office"/&\nAUTOSTART="Netherlands"/' file.txt
#AUTOSTART="all"
#AUTOSTART="none"
#AUTOSTART="home office"
AUTOSTART="Netherlands"
I assumed you meant "
instead of ”
.
If you meant ”
:
$ sed 's/"home office”/&\nAUTOSTART=”Netherlands”/' file.txt
#AUTOSTART="all"
#AUTOSTART="none"
#AUTOSTART="home office”
AUTOSTART=”Netherlands”
Upvotes: 0