Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

zgrep multiple patterns issue

Tags:

grep

I am new in the Linux world and I have an issue

I have a lot of files, like 20 of them, which start with the same name only changing a few characters at the end of the name. All this files are in .tar.gz format.

In this files there are lots of information which are written like this

1234|123415|12356|abcd|abcde|....|

I'd like to grep this files looking for matches in all of them, I have more than one pattern and this is where my problem starts

Due to the fact that these are .tar.gz files I cannot make a regular grep, and I need a zgrep for this, therefore I found the next code

zgrep -a *pattern* *file*

Which works fine, but only with one pattern, if I try to use it with multiple patterns it just doesn't work.

Can you help me to make something like the next code works:

zgrep -a *pattern1* *pattern2* *file*
like image 483
Antonio Perez Oseguera Avatar asked Jul 11 '13 20:07

Antonio Perez Oseguera


1 Answers

When matching for multiple patterns, I find it easier to use the -E extension which allowsme to use regexes. Then I can do something like:

zgrep -a -E '*pattern1*|*pattern2*|...' *file*
like image 156
Rob Di Marco Avatar answered Jan 03 '23 10:01

Rob Di Marco