gzgrep for multiple patterns or with pattern file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting gzgrep for multiple patterns or with pattern file
# 1  
Old 03-31-2010
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.
# 2  
Old 03-31-2010
You can pipe the file through gunzip first, so you can use your preferred versions of grep instead:

Code:
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.
# 3  
Old 03-31-2010
Hi, thanks for suggestion but there's also the possibility I'll need to gzgrep a compressed file in a tar file

eg:

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

but obviously the gzgrep -f doesn't work....
# 4  
Old 03-31-2010
My solution still works.

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

# 5  
Old 03-31-2010
Ahhhhh. ofcourse ! Thank you Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep multiple patterns(file) and replace whole line

I am able to grep multiple patterns which stored in a files. However, how could we replace the whole line with either the pattern or new string? For example: pattern_file: *Info in the () is not part of the pattern file. They are the intended name to replace the whole line after the pattern... (5 Replies)
Discussion started by: wxboo
5 Replies

2. Shell Programming and Scripting

Egrep patterns in a file and limit number of matches to print for each pattern match

Hi I need to egrep patterns in a file and limit number of matches to print for each matched pattern. -m10 option is not working out in my sun solaris 5.10 Please guide me the options to achieve. if i do head -10 , i wont be getting all pattern match results as output since for a... (10 Replies)
Discussion started by: ananan
10 Replies

3. Shell Programming and Scripting

Grep from multiple patterns multiple file multiple output

Hi, I want to grep multiple patterns from multiple files and save to multiple outputs. As of now its outputting all to the same file when I use this command. Input : 108 files to check for 390 patterns to check for. output I need to 108 files with the searched patterns. Xargs -I {} grep... (3 Replies)
Discussion started by: Diya123
3 Replies

4. Shell Programming and Scripting

Find common patterns in multiple file

Hi, I need help to find patterns that are common or matched in a specified column in multiple files. File1.txt ID1 555 ID23 8857 ID4 4454 ID05 555 File2.txt ID74 4454 ID96 555 ID322 4454 (4 Replies)
Discussion started by: redse171
4 Replies

5. Shell Programming and Scripting

How to search multiple patterns and remove lines from a file?

Hi, I have a file content as below. Table : PAYR Displayed fields: 15 of 15 Fixed columns: 4 List width 0999... (4 Replies)
Discussion started by: shirdi
4 Replies

6. Shell Programming and Scripting

Awk to Count Multiple patterns in a huge file

Hi, I have a file that is 430K lines long. It has records like below |site1|MAP |site2|MAP |site1|MODAL |site2|MAP |site2|MODAL |site2|LINK |site1|LINK My task is to count the number of time MAP, MODAL, LINK occurs for a single site and write new records like below to a new file ... (5 Replies)
Discussion started by: reach.sree@gmai
5 Replies

7. Shell Programming and Scripting

Searching for multiple patterns in a file

Hi All, I have a file in which i have to search for a pattern from the beginning of the file and if the pattern is found , then i have to perform a reverse search from that line to the beginning of the file to get the first occurrence of another pattern. sample input file hey what are you... (8 Replies)
Discussion started by: Kesavan
8 Replies

8. Shell Programming and Scripting

Perl - How to search a text file with multiple patterns?

Good day, great gurus, I'm new to Perl, and programming in general. I'm trying to retrieve a column of data from my text file which spans a non-specific number of lines. So I did a regexp that will pick out the columns. However,my pattern would vary. I tried using a foreach loop unsuccessfully.... (2 Replies)
Discussion started by: Sp3ck
2 Replies

9. Shell Programming and Scripting

How to cut multiple patterns from a file?

Hi, I need to cut values after searching for similar patterns in a file. For example, I have the following pattern in a file: ####<Nov12 2007> <user: Vijay> <user id:123456 college:anna univ> <error code: runtime exception> I need the values for date: User: User id: College:... (5 Replies)
Discussion started by: Vijay06
5 Replies

10. UNIX for Dummies Questions & Answers

How to parameterize multiple search patterns and generate a new file

I have one file: 123*100*abcd*10 123*101*abcd*-29*def 123*100*abcd*-10 123*102*abcd*-105*asd I would like to parameterize the search patterns in the following way so that the user could dynamically change the search pattern. *100* and *- (ie *minus) *102* and *- The output that is... (6 Replies)
Discussion started by: augustinep
6 Replies
Login or Register to Ask a Question