Search code examples
shellsedquoting

Escape < and > in sed/shell


How do I escape '<' and '>' character in sed.

I have some xml files which needs some text between the tags to be replaced. How do I escape the '>' and '<' characters.

The problem with > and < is it has special meaning in the shell to redirect the output to a file. So backslash doesn't work.


Solution

  • Ok. Found out by myself. Use quotes.

    $ sed -i "s/>foo</>bar</g" file