I'm trying to add the following line to the beginning of file using sed command:
node /^$server$/ inherits default {
Command: sed -i "1i node /^$server$/ inherits default {" "file.txt"
When I run the command locally from the server it's working for me, but when I try to run it from bash script using this command:
sudo ssh serverName sed -i "1i node /^$server$/ inherits default {" "file.txt"
I got this error message:
"sed: -e expression #1, char 2: expected \ after a',c' or `i'"
I added \ after the 1i but this just adding the word "node" to the beginning of the file.
The first line of the file need to be for example:
node /^serverName$/ inherits default {
I guess that I need to use regex in my command but I don't know how to do it.
Please assist