by Luuk <Luuk@[EMAIL PROTECTED]
>
Feb 24, 2008 at 09:16 PM
Viatly schreef:
> Given a stdout of some prog, I have to filter out 2-line blocks of
> text, where the first line contains "marker1" and the second line
> contains "marker2".
> Thus, for the following output
>
> some text..
> more text...marker1...moretext
> more text...marker2...moretext
> more text..
> more text...marker1...moretext
> more text..
> more text...marker2...moretext
> more text...
>
> after applying the filter I shell get
>
> some text..
> more text..
> more text...marker1...moretext
> more text..
> more text...marker2...moretext
> more text...
>
> For one-line case grep whould be just sufficient:
>
> ./prog | grep -v marker1
>
> however for multiline patterns I think grep is not a right choice. How
> it can be done with awk/sed?
following is untested, but should almost work:
awk '/marker1/{ mark=1 }
/marker2/{ if (mark==1) { mark=mark+1 } else { mark=0 }}
{ if (mark==2) { do something because 'marker1' was found and
'marker2' on next line.... }' file
--
Luuk