Tuesday, 10 September 2013

How do I fix sed group capturing for unnesting a LaTeX code section?

How do I fix sed group capturing for unnesting a LaTeX code section?

I have a piece of text, that I want to unnest.
\caption[Server HTTP responses]{Server HTTP responses\label{fig:http-status}}
I want sed to bump the final } so that it starts in front of label like so:
\caption[Server HTTP responses]{Server HTTP responses}\label{fig:http-status}
Using a regular expression editor against my test text, it seems that:
(\\label\{fig:[a-zA-z0-9 -]{1,}\})\}$
replaced with
\}\1
would do the trick. This works on debuggex.com and in the Mozilla Regular
Expression tester.
When I however test this with sed (I'm a complete newbie with sed, so
please go easy on me here), I use
cat ./file.tex | sed -e 's@(\\label\{fig\:[a-zA-z0-9 -]{1,}\})\}$@\}\1@g'
> test_output.txt
which returns: sed: -e expression #1, char 47: Invalid content of \{\}
What am I doing wrong here? Is there an easier way to run through a
massive text file to replace with regex?

No comments:

Post a Comment