How to find patterns across multiple lines using grep?

后端 未结 26 2073
你的背包
你的背包 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:29

    With ugrep released a few months ago:

    ugrep 'abc(\n|.)+?efg'
    

    This tool is highly optimized for speed. It's also GNU/BSD/PCRE-grep compatible.

    Note that we should use a lazy repetition +?, unless you want to match all lines with efg together until the last efg in the file.

提交回复
热议问题