Command needed to Parse Catalina.out in Linux

Hi all,

Everyday I used to parse the Catalina.out log file on my Redhat system for errors for a particular date. Could anybody be able to help me to create a command which can grep the contents of Catalina.out starting from particular date.
Please do not suggest command which greps only the lines with that date, I mean I need all the lines starting from that particular date.

Thanks,
RedHatPerl

show a sample of that file. and what you want to get.

Here is the sample what I want.... see my Catalina.out logs below, here I want to grep all the lines which start from date May 25, 2009. upto the end but I need all the lines which comes in between, otherwise I could have used this :

grep "May 25" catalina.out

But it only gives me the lines with May 25, I need all the lines starting from date May 25 to the end of May 25.

[xxx@hub tomcat]$cat catalina.out
May 24, 2009 7:30:22 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /opt/Java/1.5.0_12/jre/lib/i386/client:/opt/Java/1.5.0_12/jre/lib/i386:/opt/Java/1.5.0_12/jre/../lib/i386
May 24, 2009 7:30:22 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-localhost%2F127.0.0.1-8080
May 24, 2009 7:30:22 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 762 ms
May 24, 2009 7:30:23 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
May 24, 2009 7:30:23 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.13
May 24, 2009 7:30:24 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(/opt/Tomcat/Tomcat_Base/webapps/xfire/WEB-INF/lib/javaee.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
May 24, 2009 7:30:25 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-localhost%2F127.0.0.1-8080
May 24, 2009 7:30:25 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
May 25, 2009 1:30:25 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/27 config=null
May 25, 2009 1:30:25 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2301 ms
License file saxon-license.lic not found. Running in non-schema-aware mode

so the output you want is
May 25, 2009 1:30:25 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/27 config=null
May 25, 2009 1:30:25 AM org.apache.catalina.startup.Catalina start

right? try to describe the output you want clearly.

Yes you are right .. output I want is all the logs of date 25th May..

then how about the last 2 lines ?

INFO: Server startup in 2301 ms
License file saxon-license.lic not found. Running in non-schema-aware mode

they are part of the last "May 25" right?

Yes these all lines are part of "May 25"

If you have Python, and assuming May 26 is what comes after.

#!/usr/bin/env python
f=0
for line in open("file"):
    if "May 26" in line: break
    if "May 25" in line: f=1
    if f: print line.strip()
    

output

# ./test.py
May 25, 2009 1:30:25 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/27 config=null
May 25, 2009 1:30:25 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2301 ms
License file saxon-license.lic not found. R

with awk

awk '/May 26/{exit}/May 25/{f=1}f' file

Tried with AWK but no luck:

awk '/May 26/{exit}/May 25/{f=1}f' catalina.out
awk: syntax error near line 1
awk: bailing out near line 1

use nawk for solaris.

Hurray !! Nawk worked but how to redirect that to a text file...

nawk '/May 25/{exit}/May 24/{f=1}f' catalina.out

redirection is part of basic shell scripting. I am not going to spoonfeed you , so you have to go read up the basics.

perl -ne 'next if /^\s*$/;
          if (/^(May 25)/) {print; $in=1}
          elsif (!/^(May)/ && $in==1) {print}
          elsif (/^(May 26)/ && $in==1) {$in=0}' catalina.out

tyler_durden