Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using sed to replace the string "\UPo" by the string "\textit{Old (User's preferences)}". The command I'm using is:

find /home/rom/Desktop/nodeRemoval/report -name \*.tex -exec sed -i "s/\\UPo/\\textit{Old (User's preferences)}/g" {} \;

I want to escape the backslashes as they are part of the string. But instead of a backslash it gives me a tab! The output is: \[TAB]extit{Old (User's preferences)}

What's wrong?

Thanks in advance,


share|improve this question
up vote 2 down vote accepted

Since your expression is in double quotes, the string gets evaluated by bash (which replaces \\ with \). In fact, the regex passed on to sed looks like that:

s/\UPo/\textit{Old (User's preferences)}/g

Either escape each backslash twice:

sed -i "s/\\\\UPo/\\\\textit{Old (User's preferences)}/g"

or, better, use single quotes. Anything in single quotes will not get evaluated by bash, but beware: a single quote may not appear between single quotes, so you need to finish the single quote, escape single quote, start single quote again:

sed -i "s/\\UPo/\\textit{Old (User'\''s preferences)}/g"

This is all a bit silly, which is why we have Perl.

share|improve this answer
It works great! Thank you. Rom. – rom Sep 12 '12 at 9:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.