I’m trying to write a CLI command to change the contents of a config file.
The config file has these lines:
JAVA_OPTS="$JAVA_OPTS -XX:+UseParNewGC"
JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC"
I want to change those two lines to this one line:
JAVA_OPTS="$JAVA_OPTS -XX:+UseG1GC"
I want to replace multiple lines, so I’m trying to use Perl to do that.
perl -i -pe 's/JAVA_OPTS="\$JAVA_OPTS -XX:\+UseParNewGC"\nJAVA_OPTS="\$JAVA_OPTS -XX:\+UseConcMarkSweepGC"/JAVA_OPTS="$JAVA_OPTS -XX:+UseG1GC"/' name-of-file.sh
However, this command doesn’t change the file. I’m guessing the regular expression doesn’t match. I don’t know why. I’ve tried several variations of the command and I’ve tried escaping and double-escaping the $ and + symbols in the match string, but nothing I do makes a difference. Can someone please offer a solution?
I’m using Bash 3.2.57(1) and Perl 5.18.4 on macOS.