extract information from Unix log file based on timestamp

Dear experts -

        I have huge server log file. I would like to retrieve information from the logfile between
8/29/13 17:16:37:514 GMT  and 8/29/13 18:16:37:514 GMT.   I wanted to put the information into a different file for some error research.

        Can you please help? This is on solaris 10

Who is Participating?
Pepe2323Connect With a Mentor Commented:

My idea to get something like this will be use grep.

grep "8/29/13 17:" /var/adm/messages >> /var/tmp/message-at17.log-- i'm assuming you are looking the error on the message file

to get info of that date the whole period of 17hrs
grep "8/29/13 18:" /var/adm/messages >> /var/tmp/message-at18 to get info of that date the whole period of 18hrs

I hope this help to have a smaller log file

akp007Author Commented:
Thanks . I don't have error message to grep on. We know the error happened between the timings.

But what happens with your suggestion, it will grab all the lines that has the time stamp, but there will be some content followed by that time stamp right? , it won't be picked up.

skullnobrainsConnect With a Mentor Commented:
assuming the lines start with the dates in the provided format, this should do

sed -ne '/8\/29\/13 17:16:37:514/,/8\/29\/13 18:16:37:514/ p' /path/to/log/file

sed will start printing at the first matching line and stop likewise so you'll only get the first line timestamped at 18:16:37. if this is an issue, add one second

note that there are much more efficient ways to lookup for a date i a log file than using sed but you won't do it using shell scripting
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.