LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to extract certain lines from a log file (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-extract-certain-lines-from-a-log-file-288904/)

Avatar 02-11-2005 08:36 AM

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? :scratch:

Thank you very much

Cron 02-11-2005 09:09 AM

I think you should un-gzip it, that should do the trick :).

Avatar 02-11-2005 09:21 AM

Hah, thanks.

I unzipped it then I tried "cat messages.1 | grep "Feb 11" > newfile" and it worked.

harken 02-11-2005 09:51 AM

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


All times are GMT -5. The time now is 01:16 PM.