I know how to use grep -B n -A m match to print n and m lines before and after a match. I also know how to use sed to print from match1 until match2. But how can I combine these in a one-liner:
> cat file.txt
bar
foo
bar
baz
match1
qux
blah
bleep
match2
boop
blah
Sample Output for n=2:
bar
baz
match1
qux
blah
bleep
match2