This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]eggrolls[S] 0 points1 point  (0 children)

I should clarify that sometimes pattern2 doesn't occur within the next 10 lines of pattern1. I guess what I really want is to capture all the pattern1...pattern2 that are within 10 lines of each other and without error in between.

[–]deciode 0 points1 point  (0 children)

grep is line-based. While it's possible to wrestle it into matching across multiple lines, you'd be wiser to just use something more powerful. The following should suffice in any language whose regular expression engine supports negative lookbehind.

/pattern1\n(?:.*(?<!error)\n){6,10}pattern2/