How would I search for a certain string that is preceded by another string, in most cases several lines up, and followed by another string, i.e. contained in a certain environment?
\begin{quote}
%several lines of text
\footnote{%
%probably a few more lines of footnote content
}
%several lines of further text
\end{quote}
Thus I am searching for footnotes (starting with \footnote{
) contained in a quote environment (starting with \begin{quote}
, ending with end{quote}
, in most cases spanning over several lines). Actually, in reality I should search for another environment contained in footnotes which occur inside quote environments, thus adding a second layer of conditions, but probably once I understand the simplified example I can figure out my real world problem. The actual environment I search for occurs about 150 times in a directory containing about 20 .tex
files, constituting the sources for a roughly 500 pages book supposed to go to print in a few days, and that particular combination produces an undesired effect, which many times, if not looking carefully, will go unnoticed.
As output of my search I would like to get the file name in which the match occurs (I would probably search through *tex
, although, if that should be too complicated, I could also work with a bash for loop), and its line number.
One will also have to keep in mind that
\begin{quote}
%something
\end{quote}
%something
\footnote{%
%something
}
%something
\begin{quote}
%something
\end{quote}
would be something occurring many times, but it would be a false positive.