How to find and replace all percent, plus, and pipe signs?

Viewed 26533

I have a document containing many percent, plus, and pipe signs. I want to replace them with a code, for use in TeX.

  • % becomes \textpercent.
  • + becomes \textplus.
  • | becomes \textbar.

This is the code I am using, but it does not work:

sed -i "s/\%/\\\textpercent /g" ./file.txt
sed -i "s/|/\\\textbar /g" ./file.txt
sed -i "s/\+/\\\textplus /g" ./file.txt

How can I replace these symbols with this code?

3 Answers
Related