I am writing a script to reformat some files. The details aren't important other than that the content replacing what is there contains newlines. Sed interprets the newlines as terminating the sed command and returns an error. I first tried this in gitbash on Windows, and then on CentOS 7. The below output shows the sed command failing once the newline is in the input file.
$ echo foobar > foobar.txt $ echo foo | sed "s/foo/$(cat foobar.txt)/" foobar $ echo barfoo >> foobar.txt $ cat foobar.txt foobar barfoo $ echo foo | sed "s/foo/$(cat foobar.txt)/" sed: -e expression #1, char 12: unterminated `s' command
I would want the output to be
Is there an easy way (hacks are fine - this isn't for production) to convert the newlines to
\n or escape them some other way?