I have a file like this:
text1 text2 Pattern1 text3 text4 Pattern1 text5 text2 text6 Pattern1 text7 text8 Pattern2 text2 text9 text10 text2 Pattern1 text11 text12 Pattern1 text13 text14 Pattern1 text15 text16 Pattern2 text1 text2 Pattern1 text3 text4 Pattern1 text5 text6 Pattern1 text7 text2 text8 Pattern2 text21 text22 I want to print ONLY
Pattern1 text7 text8 Pattern2 Pattern1 text15 text16 Pattern2 Pattern1 text7 text2 text8 Pattern2 i.e. if Pattern1 is followed by Pattern2, then print lines between Pattern1 and Pattern2. I don't want lines if Pattern1 is followed by Pattern1.
An awk command is highly appreciated.
I was trying like:
awk '/Pattern1/,/Pattern2' file \> output but it gives all the lanes that appear between two successive Pattern1 also.