I wanted to apply changes to config file with SED command, it requires inserting some lines in a few places after starting tags.
However, when I've tried:
sed '/\[httpd/\]/a secure_rewrites = false; /\[couchdb/\]/adelayed_commits = false' local.ini
I've found out, that after [httpd] a line was appended:
secure_rewrites = false; [couchdb]/a delayed_commits=false
which is obviously not what I've intended.
Is it possible to chain append commands?
Best Answer
Using GNU
sed
(BSDsed
will not add newlines after the added text, unless you include a literal newline in the string that is added):If the file contains
initially, then the above
sed
command will produceAlso note that the
a
command for appending text is supposed to be writtena\
followed by the text appended. GNUsed
is forgiving about omitting the\
.As a
sed
script (works in anysed
):This could be use on the command line as a literal single quoted
sed
script string (a newline has to come after the last line), or stored separately and fed intosed
usingWith
#!/usr/bin/sed -f
, as the first line (assuming the path tosed
is correct), the script could even be run directly: