# \t string with sed

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,

Rom

-
add comment

## 1 Answer

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.

-
It works great! Thank you. Rom. –  rom Sep 12 '12 at 9:14
add comment