I'd like to do the following:
Given a file with many lines, several of which match a pattern, output the first matching line, the last matching line, and all the lines in between (I want them in their original order, I don't mean I want to rearrange the output). I know I can output surrounding context with grep, but I want one contiguous set of lines as output
Any help appreciated :)
edit: Example:
#PATTERN: 'ZZZZZ'
#INPUT:
foo
foo bar
foo bar ZZZZZ baz
foo bar foo
foo ZZZZZ
bar
ZZZZZ
foo ZZZZZ
foo bar baz
foo
#OUTPUT:
foo bar ZZZZZ baz
foo bar foo
foo ZZZZZ
bar
ZZZZZ
foo ZZZZZ