Here's the setup, I have two variables:
$ echo "${ORIGINALSTRING}"
placeholdertext
$ echo "${REPLACEMENTSTRING}"
-----BEGIN CERTIFICATE-----
thisisarandombase64encodedstring
blahblahblahblahblahblahblahblah
blahblahblahblahblahblahblahblah
blahblahblahblahblahblahblahblah
blahblahblahblahblahblahblahblah
-----END CERTIFICATE-----
I need to replace the original string that exists inside of a text file with a string containing multiple lines. I ran into a dead end with sed
:
$ sed -i "s/${ORIGINALSTRING}/${REPLACEMENTSTRING}/g" ./somedir/file.txt
sed: -e expression #1, char 48: unterminated `s' command
I tried maybe two dozen variations on that same command, but eventually I found out it was caused by one of the environment variables having multiple lines. So, sadly sed
is out.
Does anyone have any other ideas on how to go about accomplishing this task? I heard that maybe awk
can do what I want it to, but I haven't seen any good examples related to my specific use case.