How to find patterns across multiple lines using grep?

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

    #!/bin/bash
    shopt -s nullglob
    for file in *
    do
     r=$(awk '/abc/{f=1}/efg/{g=1;exit}END{print g&&f ?1:0}' file)
     if [ "$r" -eq 1 ];then
       echo "Found pattern in $file"
     else
       echo "not found"
     fi
    done
    

提交回复
热议问题