Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-09-2012
Registered User
 

Join Date: Jun 2008
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
zgrep for multiple exact matches

I have a few gigs of *.gz files and I want to extact a list of IP addresses from it. The command I am using is kind of working but it is not extracting the exact results.

For example, I have been using the follwing command;


Code:
zgrep --no-filename -e 10.0.0.9 -e 10.0.0.15 -e 10.0.0.244 -e 10.0.0.18 -e 10.0.0.200 -e 10.0.0.111 -e 10.0.0.18 *.gz > outputfile.out

But I noticed in the output file it will also include addresses additional to my request. For example if I specify 10.0.0.9 with -e it will also output 10.0.0.90. How can I structure my command to extract the exact input data?
Sponsored Links
    #2  
Old 02-09-2012
ahamed101's Avatar
root is god!!!
 

Join Date: Sep 2008
Location: India
Posts: 1,478
Thanks: 33
Thanked 382 Times in 377 Posts
If the lines end with the IP address, then you can try this...

Code:
zgrep -e "10.0.0.9$" *.gz

If not, show us how the line looks like...

--ahamed
Sponsored Links
    #3  
Old 02-09-2012
Scrutinizer's Avatar
mother ate her
 

Join Date: Nov 2008
Location: Amsterdam
Posts: 5,371
Thanks: 80
Thanked 1,107 Times in 1,011 Posts
Try word matching

Code:
zgrep -w -F -f random_ip.txt *.gz

does your grep support -o ?

Code:
zgrep -w -o -F -f random_ip.txt *.gz

    #4  
Old 02-09-2012
Registered User
 

Join Date: Jun 2008
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by ahamed101 View Post
If the lines end with the IP address, then you can try this...

Code:
zgrep -e "10.0.0.9$" *.gz

If not, show us how the line looks like...

--ahamed
I found another way, your method works but it takes extremely long on huge and lots of files, not sure how it reads it.

This method works by reading from a list of IP addresses that you want to grep;

zgrep -w -F -f iplist.txt *.gz > iplist.out
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Changing exact matches with awk from subfields adamreiswig Shell Programming and Scripting 4 01-24-2012 04:29 PM
grep multiple matches santonio UNIX for Dummies Questions & Answers 2 01-29-2011 06:32 AM
Using grep returns partial matches, I need to get an exact match or nothing TKD Shell Programming and Scripting 3 01-25-2011 11:52 AM
Multiple arguments passed to zgrep in sh/ksh linux_lou Programming 1 02-09-2010 02:29 PM
Does Sed Search/Replace Work For Multiple Matches On The Same Line? cibalo Shell Programming and Scripting 3 06-06-2009 03:38 AM



All times are GMT -4. The time now is 04:49 AM.