Lets say I have fileA, with the contents
Hello, this is some
random text REPLACEHERE and some more
random text
and fileB with the contents
stuff that goes into
fileA, at that specific place
How do I properly replace REPLACEHERE inside fileA, with the contents of fileB ? Exactly in that place, just as if I was doing a simple regex operation ?
The closest I’ve got was
sed -i '/REPLACEHERE/r fileB' fileA
which only ends up appending fileB in the line after REPLACEHERE was found, and that’s no good. I need it to be replaced exactly in place (I thought that’s what the i flag was for actually).
It probably won’t be that easy with
sedonly, I’d use a shell variable/command expansion:-imeans that the changes will be saved tofileA, rather than printed tostdout.Mind the slashes in
fileB, by the way. If there are any, they will have to be escaped.