I want to do replace for the following patterns (the foregoing rule has higher priority)
\right) -> remain unchanged
\right ) -> remain unchanged
\right] -> remain unchanged
\right ] -> remain unchanged
\right} -> remain unchanged
\right } -> remain unchanged
\ri) -> \right)
\ri -> \rightarrow
\right -> \rightarrow
In other words, if there is any parentheses bracket or brace, I want to have \right, if anything else, it should be replaced by \rightarrow. In short, I was trying transform a lot of shorthanded google doc equations with into proper LaTeX format. What I came up with was the following
sed -i 's/\\ri\([^g]\)/\\right\1/g' $tempfile1 #first step substitution
sed -i 's/\\right\([^])}>|a]\)/\\rightarrow\1/g' $tempfile1
sed -i 's/\\right \([^])}>|a]\)/\\rightarrow \1/g' $tempfile1
It works ok except it does not change \right\ into \rightarrow\ as expected. My test input tempfile1 is the following
\ri\right\right \right)\right]\right }\right )\ri \right ]\righta \al \\
It goes into
\rightarrow\right\rightarrow \right)\right]\right }\right )\rightarrow \right ]\rightarrow \alpha \\
Noting that the \right\ part was not done correctly. Then I added the following line, thinking that it will explicit pick up what was left, however, it does not work as expected and now I am really confused...
sed -i 's/\\right\\/\\rightarrow\\/g' $tempfile1 #why this does not work
Thanks a lot in advance!
sed -i -e '...pattern1...' -e '...pattern2...' -e '...pattern3...' ...
. For kilobyte-size files, three passes probably don't matter much, but for multi-megabyte files and bigger, one pass vs three can make a big difference.