• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Log between two Time

 
Ranch Hand
Posts: 42
Android Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
nazzy khan
Ranch Hand
Posts: 42
Android Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tim for giving some suggestions...

I'll look into that and will let you know


-nazzy
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using OtrosLogViewer with timefilter. This is a Swing desktop application, but it can open files from SSH/SFTP servers.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic