Search code examples
shellperlawkgrep

Grep lines only if containing 2 specific strings


Is it possible to grep lines only if containing 2 specific strings in it?

I have logs like this and I would like to grep only lines containing strings "13/Dec/2022:11" AND "GET /fr/test"

access.log:site.ch 111.222.333.444 - - [13/Dec/2022:11:40:00 +0100] "GET /fr/test HTTP/1.1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"

Solution

  • Just grep twice:

    | grep "13/Dec/2022:11" | grep "GET /fr/test"
    

    Or combined with zgrep

    zgrep "13/Dec/2022:11" * | grep "GET /fr/test"