I'm trying to get sed
to replace a line in a file with the contents of another file. Got this to work, however the in-place replacement somehow produces an extra file with -e
suffixed.
This only seems to happens on macOS (High Sierra), and doesn't happen on Linux (Alpine) as I tried to reproduce this in a docker container.
My commands that reproduce this in sequence:
$ echo 'someline' > target_file.txt
$ echo 'replacementcontent' > replacement.txt
$ sed -Ei -e "\#^someline\$#{
r replacement.txt
d
}" target_file.txt
$ cat target_file.txt
replacementcontent
$ ls
replacement.txt target_file.txt target_file.txt-e
The replacement worked as intended but in a Linux environment the target_file.txt-e
would not be there.
I know there are differences between the macOS and Linux sed, but this just seems random but I'm likely just not understanding something.
Why does this happen, and can the command be written in an agnostic way (so that it works the same on both macOS and Linux)?