Search for text between two patterns with multiple lines in between

后端 未结 3 1961
[愿得一人]
[愿得一人] 2021-01-28 15:15

I have a simple question. I have a file containing:

more random text

*foo*
there
is 
random
text
here
*foo*

foo
even
more
random
text
here
foo
more random text         


        
3条回答
  •  逝去的感伤
    2021-01-28 15:56

    Since checking for "foo" (using /foo/) is relatively expensive, the following avoids that check and will work with all awks worthy of the name:

    awk 'c==2 {next} /foo/{++c;next} c==1' file
    

提交回复
热议问题