I know that stackexchange is filled with helpful stuff about how to do things similar to what I want to do, but I'm afraid I'm not skilled enough to extrapolate from them and solve my problem.
I'm trying to write a script that searches for specific latex definitions, contained in one or more .sty files, and then return the entire definition. The definition is contained inside curly brackets, but there may be lots of curly brackets inside of the definition.
For example, following this thread I tried the command
sed -n '/\\def\\propref\>/,/}$/p' *.sty
but this returns
\def\propref#1{%
\IfBeginWith*{#1}{prop:}
But I want it to return the entire definition, delimited by {}, i.e.,
\def\propref#1{%
\IfBeginWith*{#1}{prop:}
{Prop.~\ref{#1}}%
{Prop.~\ref{prop:#1}}}
So, the hard part for me is to locate the closing delimiter that matches the opening one. A second issue, if the solution is to use sed, is that I'd like the command to return the file name as well as the pattern, just as grep does, when searching thru multiple files. Specifically, I'll like the first line of the returned output to look grep-like
my_oneLineDefs.sty:\def\propref#1{%
Here's a snippet of the .sty file containing the definition.
\def\propref#1{%
\IfBeginWith*{#1}{prop:}
{Prop.~\ref{#1}}%
{Prop.~\ref{prop:#1}}}
\def\thmref#1{%
\IfBeginWith*{#1}{thm:}
{Thm.~\ref{#1}}%
{Thm.~\ref{thm:#1}}}
\def\secref#1{%
\IfBeginWith*{#1}{sec:}
{\S\ref{#1}}%
{\S\ref{sec:#1}}}