2

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?

0

1 Answer 1

1

You need to escape both the shell, and sed:

$ A=w
$ B="\\\ "
$ echo word | sed "s/$A/$B/"
\ ord

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.