Given that you have:
line="Some Text that should be changed \\"
so your echo "$line"
yields:
Some Text that should be changed \
Then sed
sees:
sed -i "s/Some Text that should be changed \/Your replacement/" yourfile
and the backslash means that your search pattern hasn't ended, and therefore the substitute command is malformed - as the error message says.
You will have to get a second backslash onto the end of the string. One of a myriad ways of doing that is:
case "$line" in
(*\\) line="$line\\";;
esac
This is just being inventive...but it has the merit of not executing any external command to fix the string. There are also more direct substitutions available in bash
.
Now you can do:
sed -i "s/^$line$/$newline/" $myFile
and as long as $newline
contains neither any slashes nor any backslashes, you will be safe enough.