I can do this for example

sed 's/\>\</\>\

To replace >< with


However, say I want a variable, like this:

 sed 's/\>\</\>\

It will interpret it as literally $1. To fix this, I use " instead of '.

Like this:

sed "s/\>\</\>\

But it doesn't understand the newline when I use ". \n does not work either.

  • "it doesn't understand the newline".. does it understand \n?
    – muru
    Dec 12, 2015 at 0:32
  • @muru No, I already said that. It interprets it as a literal \n. Same thing with -e if that would change anything. Dec 12, 2015 at 0:33
  • Yep, didn't notice that. Which shell are you using? sed will only get the pattern after the shell does quote removal, etc., so if quoting causes a problem, the shell is probably the culprit.
    – muru
    Dec 12, 2015 at 0:36
  • @muru I am using bash. Dec 12, 2015 at 0:39
  • What if you do 's/></>\[enter]<'"$SHELL/g"?
    – muru
    Dec 12, 2015 at 0:44

1 Answer 1


I'm not sure what quoting mystery is behind this, but if single quotes help with the newline, you can mix and match with double quotes for the variable:

sed 's/></>\
  • 1
    double-quotes eat backslash escaped newlines. "This" == "T\\nhis"
    – mikeserv
    Dec 12, 2015 at 17:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .