Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 02-11-2005, 09:36 AM   #1
Registered: May 2001
Location: Canada
Distribution: old ones
Posts: 532

Rep: Reputation: 30
how to extract certain lines from a log file

Hi there

I want to extract some lines from a log file pertaining to a certain date and time frame. The log file is /var/log/messages and it's huge: 7.4 MB gzipped, or 973,367 lines.

I would like to extract, say, Feb 11 between 5-6 AM and save in another file or even view it on the command line (like with vi or something)

I tried "cat messages.1.gz | grep "Feb 11"" and it didn't do anything.

What about for a certain date (Feb 11) and some other entry in the line, for instance, a certian IP address? grep Feb 11 | grep

Thank you very much
Old 02-11-2005, 10:09 AM   #2
Registered: Jun 2004
Location: Lithuania
Distribution: FreeBSD, Arch, Ubuntu
Posts: 145

Rep: Reputation: 15
I think you should un-gzip it, that should do the trick .
Old 02-11-2005, 10:21 AM   #3
Registered: May 2001
Location: Canada
Distribution: old ones
Posts: 532

Original Poster
Rep: Reputation: 30
Hah, thanks.

I unzipped it then I tried "cat messages.1 | grep "Feb 11" > newfile" and it worked.
Old 02-11-2005, 10:51 AM   #4
Registered: Jan 2005
Location: Between the chair and the desk
Distribution: Debian Sarge, kernel 2.6.13
Posts: 666

Rep: Reputation: 30
For grepping through gzipped files use the 'zgrep' command. It basically has the same syntax with grep.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Assistance with extracting a series of lines from a log file katsal Linux - General 1 06-21-2005 07:55 PM
how to extract the name of the file bahadur Programming 9 03-22-2005 07:48 PM
/etc/securetty --> I commented out all lines and I can still log in as root adamrau Linux - Security 2 05-30-2004 07:16 AM
Extract file Electboy Linux - General 1 07-21-2003 06:51 PM
How do you extract a file? Neb Linux - Newbie 9 05-14-2003 04:46 PM

All times are GMT -5. The time now is 09:59 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration