How to find patterns across multiple lines using grep?

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

    I used this to extract a fasta sequence from a multi fasta file using the -P option for grep:

    grep -Pzo ">tig00000034[^>]+"  file.fasta > desired_sequence.fasta
    
    • P for perl based searches
    • z for making a line end in 0 bytes rather than newline char
    • o to just capture what matched since grep returns the whole line (which in this case since you did -z is the whole file).

    The core of the regexp is the [^>] which translates to "not greater than symbol"

提交回复
热议问题