2

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

2

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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