I have to create a script to replace several lines in apache’s httpd.conf
file. I have 2 problems. First, how I can save several lines into a single variable? I tried this, but it didn't work
replace="#ErrorLog "logs/error_log" '\n' ErrorLog "|<apache_location>/bin/rotatelogs <apache_location>/logs/error.%Y.%m.%d.log 86400"
The '\n'
didn’t work to add a line break. Then my idea is use sed(1) like this:
sed -i "s#ErrorLog "logs/error_log"#$replace#g" $apache_httpd
I don’t know whether this will work.
I was able to create the variable with several lines:
VAR="#ErrorLog \"logs/error_log\""
VAR="$VAR"$'\n'"ErrorLog \"|<apache_location>/bin/rotatelogs <apache_location>/logs/error.%Y.%m.%d.log 86400\""
replace="ErrorLog \"logs/error_log\""
Now the problem comes with the sed, I had to use a different delimiter (http://backreference.org/2010/02/20/using-different-delimiters-in-sed/). But it keep failing.
sed -i "s;$replace;$VAR;g" /root/daniel/scripts/test3/httpd.conf
sed: -e expression #1, char 54: unterminated `s' command
perl -i.orig -ple 's/foo/bar/g' somefiles
.