Sed replaces tex with short arm $$ latex with short arm \ (\)

I am currently having a problem editing files manuscript.tex

. Until now, I have always used short $$ text; however, something comes in and I need to replace all $ ... $ with \( \)

.

I think "sed" with a replace operation should be the right tool for the task. However, I am not very familiar with sed and regex. So I need hints and helps with this.

Suppose the input file has a name manuscript.tex

. I need to "sed" replace $ e=mc^2 $

on \( e=mc^2 \)

. How can i do this?

+3


source to share


2 answers


If there is never a newline between dollar signs, you can try something like



sed -e 's/\$\([^$]\+\)\$/\\(\1\\)/g' manuscript.tex > manuscript2.tex

      

+1


source


Another way to use sed



sed -re 's/(.*)\$(.*)\$(.*)/\\(\2\\)/g' temp.txt

+1


source







All Articles