File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Linux / UNIX and the fly likes Log between two Time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Log between two Time" Watch "Log between two Time" New topic
Author

Log between two Time

nazzy khan
Ranch Hand

Joined: May 06, 2010
Posts: 39

Hi,

How do I grep log between two times.

Say, I want logs between 18 Feb 2011 12:40 and 18 Feb 2011 22:28

I have tried this by egrep, sed and awk but could not get the right logs.


awk '/18\/Feb\/2011:12:40:/, /18\/Feb\/2011:22:28:/' app_server.log | grep -i "error"

It gives me error says... awk: record `2011-02-18 00:00:15,...' too long



Any idea how to get logs between two timestamp...

Thanks

-nazzy
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16065
    
  21

Grep doesn't parse timestamps, and neither will your AWK script. You're going to need something more intelligent.

Some Linux distros came with a log viewer app that might be able to help, but I don't know what's available at the moment. I think the viewer may have been named something like "sawmill".

Failing that, you could write a perl or python script that parsed the dates and filtered lines. Or, for that matter, a Java Application using the DateParser class. Probably doable in about 100 lines of Java.

AWK might be able to handle the date parsing, too, but it would be a lot of work, I think.


Customer surveys are for companies who didn't pay proper attention to begin with.
nazzy khan
Ranch Hand

Joined: May 06, 2010
Posts: 39

Thanks Tim for giving some suggestions...

I'll look into that and will let you know


-nazzy
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Maybe I didn't get the question right, but this works for me:

Yes, you have to know in advance whether those timestamps are present in the logfile, because the patterns aren't regarded as date/time, but simply as strings. Filter from this to that string.



http://home.arcor.de/hirnstrom/bewerbung
Krzysztof Otrebski
Greenhorn

Joined: Jun 06, 2012
Posts: 4
I'm using OtrosLogViewer with timefilter. This is a Swing desktop application, but it can open files from SSH/SFTP servers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Log between two Time