Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Like this, just one awk:

awk '/13\/Dec\/2022:11/ && /GET \/fr\/test/' file

or one perl:

perl -ne 'print if m|13/Dec/2022:11| and m|GET /fr/test|' file

or one sed:

sed -n '/13\/Dec\/2022:11/,/GET \/fr\/test/p' file

or with one zgrep or grep:

zgrep -E '13/Dec/2022:11.*?GET /fr/test' file
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading