I have a text file that looks like this:
-+- beginning text
hey there
hi there
ho there
-+- ending text
other stuff
that is
immaterial for
my purposes
I want to only grab the lines between the -+- patterns, so it will return:
hey there
hi there
ho there
The standard awk way:
awk '/beginning text/ {flag=1;next} /ending text/ {flag=0} flag {print}'
Works great as long as "beginning text" and "ending text" are different patterns.
Alas, for what I need, "Beginning text" and "Ending text" can change. The only consistent part of the two lines are the "-+-". All the rest of the text in the file can be completely different; I can't rely on any consistent patterns. The only reliable text is the -+-. And the awk fails when the two strings are identical.
Any ideas for how I can returns the lines between two discrete instances of the same pattern exclusive of the lines containing the patterns? Doesn't have to be awk, just something that will work in a bash shell script.