My original answer was to be the following script, totally equivalent to the answer by Ethan Bolker, which posted when I was writing it.
/.*begin{figure}/{
output=1
}
output==1{
print
}
/.*end{figure}/{
output=0
print "% ---------------------------------- "
}
I cancelled my answer, but the OP asked me to post it nevertheless, so here it is.
In order to provide some added value, I'll post also the following variation, which deals with some rare cases (not really needed, I implemented it only for fun), in particular:
- It strips extraneous chars which could appear at the beginning of
\begin{figure} or the end of \end{figure}
- It does not output
figure environments inside verbatim, Verbatim or lstlisting.
BEGIN{
in_verbatim=0
}
/.*begin.(verbatim|Verbatim|lstlisting)/{
in_verbatim=1
}
/.*end.(verbatim|Verbatim|lstlisting)/{
in_verbatim=0
}
/.*begin.figure./{
if (! in_verbatim) {
output=1
split($0, aux, "begin{figure}")
print "\\begin{figure}" aux[2]
}
next
}
/.*end.figure./{
output=0
if (! in_verbatim) {
split($0, aux, "end{figure}")
print aux[1] "end{figure}"
print "% ---------------------------------- "
}
}
output==1{
print
}
\usepackage{endfloat}will do it for you, writing afilename.ffffile containing exactly what you need. – egreg Jan 10 at 14:19fffcontains\begin{figure*}even if I use non stared environment. – Sigur Jan 10 at 14:23\end{figure}is on a line by itself and starting at column 1, which isn't so bad a requirement. You don't indent all yourdocumentenvironment, do you? – egreg Jan 10 at 14:33