I thought the following would work, but I could not get a look-behind expression to work if it contained a newline.
mycmd | pcregrep -M '(?<=^/ > -{7}\n).*\n(?=/ > $)'
But the following two stage solution worked for me:
mycmd | pcregrep -M '^/ > -{7}\n.*\n/ > $' | pcregrep -v '^/ >'
Update in response to OP's answer
I like the \K escape :-)
I assume you do not want to match the following situation
/ > -------
/ > perhaps text here
/ >
I was able to get negative look ahead to work when it contains \n, even when it is embedded within a positive look ahead.
Here is a simpler regex with \K
that is closer to what you want. It disallows any content after the / >
, but it still allows lines before the / > -------
.
mycmd | pcregrep -Mo '^/ > -{7}\n\K(?!/ >).+(?=\n/ > $(?!\n[\s\S]))'
If the captured line should be allowed to start with / >
, then it is simpler:
mycmd | pcregrep -Mo '^/ > -{7}\n\K.+(?=\n/ > $(?!\n[\s\S]))'
Final update
Here is a sed one liner that I believe gives the exact result, disallowing any extra lines before or after. However, it does allow capturing a line that begins with / >
.
mycmd | sed -n '1{/^\/ > -\{7\}$/{n;/./{h;n;/^\/ > $/{${x;p}}}}}'
And here is another sed solution
mycmd | sed -n '1{h;n;H;x;N;${/^\/ > -\{7\}\n..*\n\/ > $/{x;p}}}'