Sed - replacing a string with a variable full of weird characters
One possibility is to use bash instead of sed
. That makes the substitution easy, but you'll have to emulate the -i
option.
Something like this:
TMPFILE=$(mktemp)KEY=$(cat keyfile)while IFS= read -r LINE; do echo "${LINE//stringtoreplace/$KEY}"done </path/to/file >$TMPFILEmv $TMPFILE /path/to/file