LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 02-11-2005, 08:36 AM   #1
Avatar
Member
 
Registered: May 2001
Location: Canada
Distribution: old ones
Posts: 555

Rep: Reputation: 33
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 192.168.1.123?

Thank you very much
 
Old 02-11-2005, 09:09 AM   #2
Cron
Member
 
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, 09:21 AM   #3
Avatar
Member
 
Registered: May 2001
Location: Canada
Distribution: old ones
Posts: 555

Original Poster
Rep: Reputation: 33
Hah, thanks.

I unzipped it then I tried "cat messages.1 | grep "Feb 11" > newfile" and it worked.
 
Old 02-11-2005, 09:51 AM   #4
harken
Member
 
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.
 
  


Reply



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 06:55 PM
how to extract the name of the file bahadur Programming 9 03-22-2005 06:48 PM
/etc/securetty --> I commented out all lines and I can still log in as root adamrau Linux - Security 2 05-30-2004 06:16 AM
Extract file Electboy Linux - General 1 07-21-2003 05:51 PM
How do you extract a file? Neb Linux - Newbie 9 05-14-2003 03:46 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:14 AM.

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