Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
google site



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-27-2009
Registered User
 

Join Date: Jul 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
How to perform Grep on many Gzip files, Searching for Specific information

Hello,

I am wondering if you can assist with my question and ask kindly for this.

I have a number of files that are listed as file1.gz through file100.gz.

I am trying to perform a grep on the files and find a specific date that only resides within within one of the files. There are multiple entries within the file so I am try to also limit the amount of output with the tail or head command.


My command is something like this, although it is incorrect:

gunzip -c file1.*.gz |grep -v "Jul 25 22:16:09" | tail -n 20


Thank you kindly.
Sponsored Links
  #2  
Old 07-27-2009
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 6,729
Thanks: 0
Thanked 53 Times in 50 Posts
You want the name of the file that has Jul 25 22:16:09 in it correct?


Code:
for filename in file*.gz
do
    gunzip $filename | grep -q 'Jul 25 22:16:09'
    if [[ $? -eq 0 ]] ; then
        echo $filename
        break
    fi
done

  #3  
Old 07-27-2009
Registered User
 

Join Date: Jun 2009
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
You might look at zgrep to simplify your answer (assuming it's available on your platform)


Code:
zgrep "Jul 25 22:16:09" file1.*.gz | tail -n 20

More info:

The Power of Z Commands – Zcat, Zless, Zgrep, Zdiff Examples
zgrep(1) - Linux man page
  #4  
Old 07-27-2009
Registered User
 

Join Date: Jul 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks much to those that responded.

Will try what was suggested and advise.

Best regards.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perform a set of actions for a specific file type oehtus Shell Programming and Scripting 2 06-15-2009 11:07 AM
Searching for package information on Debian and Ubuntu systems Linux Bot UNIX and Linux RSS News 0 10-28-2008 10:20 AM
grep - searching for a specific string manthasirisha Shell Programming and Scripting 2 01-05-2006 08:24 AM
searching text files on specific columns for duplicates Gerry405 UNIX for Dummies Questions & Answers 2 08-18-2005 10:51 AM
Searching for a specific string in an argumnet dinplant Shell Programming and Scripting 1 03-11-2002 02:28 PM



All times are GMT -4. The time now is 07:30 AM.