Update::I forgot to mention - you need to slurp the file, as
hipowls(++) indicates below.
Your regex needs two changes:
- Escape the period
- Add the \s modifier.
From "perldoc perlre":
Used together, as /ms, they let the "." match any character whatsoever, while still allowing "^" and "$" to match, respectively, just after and just before newlines within the string.
This works:
s/^(if.*rctladm\.conf.*fi)/$1\n$here/sm;
However, may I suggest the following alternatives:
- Replace the entire shell script with perl.
- Insert a line at the end of the original script, that calls another (bash) script. Use perl to generate the second script. This way, the first script remains unmodified - easier to enhance and debug.
"As you get older three things happen. The first is your memory goes, and I can't remember the other two... "
- Sir Norman Wisdom