I use a string that contains \
in a sed
expression and I want to keep it in the output of sed
$ A=w
$ B="\ "
$ echo word | sed "s/$A/$B/"
ord
I want to obtain \ ord
instead of ord
.
What is the most elegant way of doing it?
I use a string that contains \
in a sed
expression and I want to keep it in the output of sed
$ A=w
$ B="\ "
$ echo word | sed "s/$A/$B/"
ord
I want to obtain \ ord
instead of ord
.
What is the most elegant way of doing it?
You need to escape both the shell, and sed
:
$ A=w
$ B="\\\ "
$ echo word | sed "s/$A/$B/"
\ ord