Grep regex NOT containing string

前端 未结 3 429
攒了一身酷
攒了一身酷 2020-12-12 12:33

I am passing a list of regex patterns to grep to check against a syslog file. They are usually matching an IP address and log entry;

grep "1         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-12 12:42

    patterns[1]="1\.2\.3\.4.*Has exploded"
    patterns[2]="5\.6\.7\.8.*Has died"
    patterns[3]="\!9\.10\.11\.12.*Has exploded"
    
    for i in {1..3}
     do
    grep "${patterns[$i]}" logfile.log
    done
    

    should be the the same as

    egrep "(1\.2\.3\.4.*Has exploded|5\.6\.7\.8.*Has died)" logfile.log | egrep -v "9\.10\.11\.12.*Has exploded"    
    

提交回复
热议问题