I'm attempting to replace a pattern in a file with the complete contents of another file using sed.
Currently I am using:
sed "s/PATTERN/`cat replacement.txt`/g" "openfile.txt" > "output.txt"
However, if the replacement file contains any characters such as '
, "
, or /
I start getting errors due to input not being sanitized.
I have been trying to use this guide to aid me, but I am finding it quite hard to follow. If I try the suggested r file
command, I just end up with a string.
What is the best way to approach this?
d
at the end ofscript.sed
file? I tried removing it and ran it and still got the same output. So, I am not sure what exactly it does. – Ramesh Aug 26 '14 at 03:49d
,PATTERN
remain in the file. – cuonglm Aug 26 '14 at 05:15PATTERN
with the content of the file, but any full line containing PATTERN with the content of the file. – Stéphane Chazelas Aug 26 '14 at 05:52