gzgrep for multiple patterns or with pattern file

Hi,

I'm struggling to find an option for gzgrep to grep compressed files for multiple patterns preferanly using a pattern file (so pattern file can be altered seperately to rest of script).

My regex patterns are say:
[^a-zA-Z0-9]4[0-9]\{15\}[^a-zA-Z0-9]
[^a-zA-Z0-9]3[74][0-9]\{13\}[^a-zA-Z0-9]

/usr/xpg4/bin/grep will accept -f option but /usr/bin/grep will not.

You can pipe the file through gunzip first, so you can use your preferred versions of grep instead:

gunzip < /path/to/file | /usr/xpg4/bin/grep -f pattern-file

Be careful not to leave any blank lines in your pattern file by accident! A blank line will cause it to match everything, a problem it took me much headscratching to realize.

Hi, thanks for suggestion but there's also the possibility I'll need to gzgrep a compressed file in a tar file

eg:

tar -xOf $tarFile $gzFile|gzgrep -n -f $patternFile

but obviously the gzgrep -f doesn't work....

My solution still works.

tar -xOf $tarFile $gzFile| gunzip | /usr/xpg4/bin/grep -n -f $patternFile

Ahhhhh. ofcourse ! Thank you :slight_smile: