How to find patterns across multiple lines using grep?

后端 未结 26 1687
你的背包
你的背包 2020-11-22 04:14

I want to find files that have \"abc\" AND \"efg\" in that order, and those two strings are on different lines in that file. Eg: a file with content:

blah bl         


        
26条回答
  •  名媛妹妹
    2020-11-22 04:30

    If you are willing to use contexts, this could be achieved by typing

    grep -A 500 abc test.txt | grep -B 500 efg
    

    This will display everything between "abc" and "efg", as long as they are within 500 lines of each other.

提交回复
热议问题