Match and Extract everything between 2 words in a file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • joeferns79
    New Member
    • Sep 2008
    • 37

    Match and Extract everything between 2 words in a file

    I had posed a similar topic some time back but I want some additional information from the input file.
    The log file is as shown...
    Code:
    [ERROR] [06 Apr 2009 09:45:56] [Trace] [WebContainer : 48] - App Number: 0
    [ERROR] [06 Apr 2009 09:45:56] [Trace] [WebContainer : 48] - Response for AE Completion No such RID Found
    [ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 20] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
    	at sun.reflect.GeneratedMethodAccessor186.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
    	at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
    	at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Compiled Code))
    	at java.security.AccessController.doPrivileged1(Native Method)
    	at java.security.AccessController.doPrivileged(AccessController.java(Compiled Code))
    	at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(ProxyUtil.java(Compiled Code))
    	at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDelegate.java(Compiled Code))
    	at $Proxy90.invoke(Unknown Source)
    nested exception is:
    infrastructure:RUN_ID_RUNTIME: A runtime exception occurred: javax.transaction.RollbackException.
            at sun.reflect.GeneratedMethodAccessor186.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
    	at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
    	at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Compiled Code))
    	at java.security.AccessController.doPrivileged1(Native Method)
    	at java.security.AccessController.doPrivileged(AccessController.java(Compiled Code))
    	at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(ProxyUtil.java(Compiled Code))
    	at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDelegate.java(Compiled Code))
    	at $Proxy90.invoke(Unknown Source)
    
    [ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 49] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
    	at sun.reflect.GeneratedMethodAccessor186.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
    	at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
    	at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Compiled Code))
    	at java.security.AccessController.doPrivileged1(Native Method)
    I want the Perl script to return everything from the file called "App.log" shown above, that matches the line containing "ID_UNHANDL ED", i.e. the line ...
    Code:
    "[ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 20] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator." 
    upto the next occurence of the string "[ERROR]" 
    i.e. it should include the following ...
    
    [ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 20] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
    ....
    ...
    ...
    nested exception is:
    infrastructure:RUN_ID_RUNTIME: A runtime exception occurred: 
    ...
    ...
    ...
    at $Proxy90.invoke(Unknown Source)
    which is the last line of that exception. It shouldn't include the next "[ERROR]" line.

    I could come up with the following code but it returned only the lines containing the strings mentioned.

    Code:
    while ($line = <LOGFILE>) {
         # chomp $line;
        if ($line =~ /^\[ERROR\](.*?)infrastructure:ID_UNHANDLED:.*$/) {
             push @message, $line;
             $match = 1;
             next;
            }
        if ($match && ($line =~ /^nested exception is:/)) {
            $line = <LOGFILE>;
            push @message, $line;
            $match = 0;
            next;
           }
        }
    Last edited by eWish; Apr 9 '09, 01:09 AM. Reason: Fixed code tags
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    its not clear if that is the entire log file or if there is more and you need to continue matching more records. If that is the entire log file then all you really need to do is use the "last" control to break the loop:

    Code:
    while ($line = <LOGFILE>) {
       if ($line =~ /^\[ERROR\](.*?)infrastructure:ID_UNHANDLED:/) {
          push @message, $line;
       }
       elsif ($line =~ /^nested exception is:/) {
          $line = <LOGFILE>;
          push @message, $line;
          last;
       }
    }

    Comment

    • joeferns79
      New Member
      • Sep 2008
      • 37

      #3
      That's not the entire log file. There are many more records like the one I showed that need to be matched. It's just that I want the entire stack to be printed and not just that 1 line.

      Comment

      • Kelicula
        Recognized Expert New Member
        • Jul 2007
        • 176

        #4
        I was just skimming the post I may be mistaken but it seems you are using a non-greedy match. Were you want a greedy match.
        Code:
        if ($line =~ /^\[ERROR\](.*?)infrastructure:ID_UNHANDLED:/) {
        Take out the question mark after the * character.
        Code:
        if ($line =~ /^\[ERROR\](.*)infrastructure:ID_UNHANDLED:/) {
        Hope it helps!

        Comment

        • joeferns79
          New Member
          • Sep 2008
          • 37

          #5
          No, it doesn't. It returns the same result ...

          [ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 20] - infrastructure: ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
          infrastructure: RUN_ID_RUNTIME: A runtime exception occurred: javax.transacti on.RollbackExce ption.
          [ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 49] - infrastructure: ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
          infrastructure: RUN_ID_RUNTIME: A runtime exception occurred: javax.transacti on.RollbackExce ption.

          i.e. it returns just the line that the string matches and not the full stack.

          I want it to return the following ...

          [ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 20] - infrastructure: ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
          at sun.reflect.Gen eratedMethodAcc essor186.invoke (Unknown Source)
          at sun.reflect.Del egatingMethodAc cessorImpl.invo ke(DelegatingMe thodAccessorImp l.java(Compiled Code))
          at java.lang.refle ct.Method.invok e(Method.java(C ompiled Code))
          at com.ibm.rmi.uti l.ProxyUtil$2.r un(ProxyUtil.ja va(Compiled Code))
          at java.security.A ccessController .doPrivileged1( Native Method)
          at java.security.A ccessController .doPrivileged(A ccessController .java(Compiled Code))
          at com.ibm.rmi.uti l.ProxyUtil.inv okeWithPrivileg e(ProxyUtil.jav a(Compiled Code))
          at com.ibm.CORBA.i iop.ClientDeleg ate.invoke(Clie ntDelegate.java (Compiled Code))
          at $Proxy90.invoke (Unknown Source)
          nested exception is:
          infrastructure: RUN_ID_RUNTIME: A runtime exception occurred: javax.transacti on.RollbackExce ption.
          at sun.reflect.Gen eratedMethodAcc essor186.invoke (Unknown Source)
          at sun.reflect.Del egatingMethodAc cessorImpl.invo ke(DelegatingMe thodAccessorImp l.java(Compiled Code))
          at java.lang.refle ct.Method.invok e(Method.java(C ompiled Code))
          at com.ibm.rmi.uti l.ProxyUtil$2.r un(ProxyUtil.ja va(Compiled Code))
          at java.security.A ccessController .doPrivileged1( Native Method)
          at java.security.A ccessController .doPrivileged(A ccessController .java(Compiled Code))
          at com.ibm.rmi.uti l.ProxyUtil.inv okeWithPrivileg e(ProxyUtil.jav a(Compiled Code))
          at com.ibm.CORBA.i iop.ClientDeleg ate.invoke(Clie ntDelegate.java (Compiled Code))
          at $Proxy90.invoke (Unknown Source)

          [ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 49] - infrastructure: ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
          at sun.reflect.Gen eratedMethodAcc essor186.invoke (Unknown Source)
          at sun.reflect.Del egatingMethodAc cessorImpl.invo ke(DelegatingMe thodAccessorImp l.java(Compiled Code))
          at java.lang.refle ct.Method.invok e(Method.java(C ompiled Code))
          at com.ibm.rmi.uti l.ProxyUtil$2.r un(ProxyUtil.ja va(Compiled Code))
          at java.security.A ccessController .doPrivileged1( Native Method

          Comment

          • Kelicula
            Recognized Expert New Member
            • Jul 2007
            • 176

            #6
            Hum....

            I think your answer lies here?

            Comment

            • joeferns79
              New Member
              • Sep 2008
              • 37

              #7
              I changed it to look like this ..
              Code:
              while ($line = <LOGFILE>) {
                   # chomp $line;
                  if ($line =~ /^\[ERROR\](.*?)infrastructure:ID_UNHANDLED: (.*)\[ERROR\]$/ms) {
                       push @message, $line;
                       $match = 1;
                       next;
                      }
                    }
              but now it won't return anything at all. Is the RE incorrect?
              Last edited by numberwhun; May 20 '09, 03:33 AM. Reason: Please use code tags!

              Comment

              • Kelicula
                Recognized Expert New Member
                • Jul 2007
                • 176

                #8
                Please use the code tags, so others can see it better and possibly use it to help you reach a solution. (copy&paste). Just an FYI.

                I think one problem may be that "$line" is always filtered in "one line at a time" but you are attempting to capture more than one line at a time, but using push to append an array one line at a time. In other words...

                No "single" line matches the criteria. You only check for match each line at a time, replacing the value of $line each iteration. Even if there was a match the multiple lines would have been pushed into message one at a time. Instead of what you want, each message element representing the whole match.

                You will have to create a result string or something.
                Like:

                [code=perl]

                my @message;

                my $file = <LOGFILE>;

                while($file =~ /^(\[ERROR\].*?infrastructu re:ID_UNHANDLED : .*?)\[ERROR\]$/mgs) {
                push(@message, $1);
                }
                [/code]

                Untested though.

                But the idea is:
                Stream the file in continuously pushing the entire match into @message, one "match" at a time.

                I removed the capturing parenthesis around the .'s, and added them around the actual match (without ending [ERROR]) So they would get captured in $1.

                You may want to match the actual double \n\n's before the next [ERROR] so the next match is successful.

                You DO still want the s and m modifiers. I added a g, for global matches.

                I have no Perl on this computer, can't test anything...sorr y.

                Comment

                • KevinADC
                  Recognized Expert Specialist
                  • Jan 2007
                  • 4092

                  #9
                  I'm still not clear on what it is you need to store in the array from the file.

                  Comment

                  • joeferns79
                    New Member
                    • Sep 2008
                    • 37

                    #10
                    Kelicula,

                    I changed it as per your suggestions, but it won't return anything at all...

                    Code:
                      sub genreport {
                    
                       my ($logfile, $reportfile) = @_;
                       my ($file, @message);
                          
                       open(LOGFILE, "<$logfile")
                          or die "Can't open $logfile: $!";
                          
                       open (REPORTFILE, ">$reportfile")
                          or die "Can't open $reportfile: $!";
                    
                       
                       while($file = <LOGFILE>) {
                         # chomp $line;
                        if ($file =~ /^(\[ERROR\].*?infrastructure:ID_UNHANDLED: .*?)\[ERROR\]$/mgs) {
                             push @message, $1;
                            
                            }
                        
                        }
                    }

                    KevinADC - I want to capture the following contents from the log ...

                    Code:
                    [ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 20] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator. 
                        at sun.reflect.GeneratedMethodAccessor186.invoke(Unknown Source) 
                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code)) 
                        at java.lang.reflect.Method.invoke(Method.java(Compiled Code)) 
                        at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Compiled Code)) 
                        at java.security.AccessController.doPrivileged1(Native Method) 
                        at java.security.AccessController.doPrivileged(AccessController.java(Compiled Code)) 
                        at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(ProxyUtil.java(Compiled Code)) 
                        at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDelegate.java(Compiled Code)) 
                        at $Proxy90.invoke(Unknown Source) 
                    nested exception is: 
                    infrastructure:RUN_ID_RUNTIME: A runtime exception occurred: javax.transaction.RollbackException. 
                            at sun.reflect.GeneratedMethodAccessor186.invoke(Unknown Source) 
                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code)) 
                        at java.lang.reflect.Method.invoke(Method.java(Compiled Code)) 
                        at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Compiled Code)) 
                        at java.security.AccessController.doPrivileged1(Native Method) 
                        at java.security.AccessController.doPrivileged(AccessController.java(Compiled Code)) 
                        at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(ProxyUtil.java(Compiled Code)) 
                        at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDelegate.java(Compiled Code)) 
                        at $Proxy90.invoke(Unknown Source)
                    The above belongs to 1 un-handled exception. But the log file contains many un-handled exceptions, so I want all these returned.
                    Last edited by eWish; Apr 14 '09, 11:25 PM. Reason: Fixed the code tags. Please use the [code][/code] tags for your data as well.

                    Comment

                    • KevinADC
                      Recognized Expert Specialist
                      • Jan 2007
                      • 4092

                      #11
                      try this:

                      Code:
                      OUTTER: while ($line = <LOGFILE>) {
                         if ($line =~ /^\[ERROR\](.*?)infrastructure:ID_UNHANDLED:/) {
                            push @message, $line;
                            while ($line = <LOGFILE>) {
                               redo OUTTER if ($line =~ /^\[ERROR\]/);
                               push @message, $line;
                            }
                         }
                      }

                      Comment

                      • Kelicula
                        Recognized Expert New Member
                        • Jul 2007
                        • 176

                        #12
                        Originally posted by joeferns79
                        Kelicula,

                        I changed it as per your suggestions, but it won't return anything at all...

                        [code=perl]
                        sub genreport {

                        my ($logfile, $reportfile) = @_;
                        my ($file, @message);

                        open(LOGFILE, "<$logfile" )
                        or die "Can't open $logfile: $!";

                        open (REPORTFILE, ">$reportfi le")
                        or die "Can't open $reportfile: $!";


                        while($file = <LOGFILE>) {
                        # chomp $line;
                        if ($file =~ /^(\[ERROR\].*?infrastructu re:ID_UNHANDLED : .*?)\[ERROR\]$/mgs) {
                        push @message, $1;

                        }

                        }
                        }

                        [/code]

                        The main thing to notice in my suggestion was this line:
                        Code:
                        my $file = <LOGFILE>;
                        Slurping the whole file into a single var, and then saying...

                        Code:
                        while(match){
                        push $message, $1;
                        }
                        In your genreport sub you are still testing for a match "one line at a time".

                        Using the s modifier allows perl's dot character to match all characters INCLUDING a newline. (which is usually the only thing excluded)

                        And the m modifier changes ^ and $ to represent the beginning and ending of ANY newline, not necessarily the next one.

                        I noticed in the LOGFILE the chunks were separated by two newlines. THAT would be a good terminator.

                        I must admit I did forget about the "holdTerminator ". $/
                        You must undefine that to properly slurp the file.
                        Slurping


                        So...
                        (tested on my computer)

                        [code=perl]
                        use strict;
                        use warnings;

                        my @message;

                        my $file = do { local $/; <DATA> }; # slurp file, undefined $/ only for this scope.

                        # while there is a match, populate message array with match.
                        while($file =~ /^(\[ERROR\].*?)\n\n/mgs) {
                        push(@message, $1);

                        }

                        $" = "\n\n"; # Added this just so I could see matches in my terminal instead of one long string.

                        print "@message";


                        __DATA__


                        kllbjbjebe ejhbbhkebef ionelf enjj kf mvg
                        e,m eikb e e3ugbgbfbjhefb f
                        ekeibejb fh eih efvfbehfuefi b kjfjnhevev
                        khefbe fikebffhebfhnem jfjdijkfj knj3vb3hyv fjbedvf
                        efjiefhne fjbefne envfmelfdihvbe ejfgv efkjlv


                        [ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 20] - infrastructure: ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
                        at sun.reflect.Gen eratedMethodAcc essor186.invoke (Unkn own Source)
                        at sun.reflect.Del egatingMethodAc cessorImpl.invo ke(De legatingMethodA ccessorImpl.jav a(Compiled Code))
                        at java.lang.refle ct.Method.invok e(Method.java(C ompil ed Code))
                        at com.ibm.rmi.uti l.ProxyUtil$2.r un(ProxyUtil.ja va(Co mpiled Code))
                        at java.security.A ccessController .doPrivileged1( Nativ e Method)
                        at java.security.A ccessController .doPrivileged(A ccess Controller.java (Compiled Code))
                        at com.ibm.rmi.uti l.ProxyUtil.inv okeWithPrivileg e(Pro xyUtil.java(Com piled Code))
                        at com.ibm.CORBA.i iop.ClientDeleg ate.invoke(Clie ntDel egate.java(Comp iled Code))
                        at $Proxy90.invoke (Unknown Source)
                        nested exception is:
                        infrastructure: RUN_ID_RUNTIME: A runtime exception occurred: javax.transacti on.RollbackExce ption.
                        at sun.reflect.Gen eratedMethodAcc essor186.invoke (Unkn own Source)
                        at sun.reflect.Del egatingMethodAc cessorImpl.invo ke(De legatingMethodA ccessorImpl.jav a(Compiled Code))
                        at java.lang.refle ct.Method.invok e(Method.java(C ompil ed Code))
                        at com.ibm.rmi.uti l.ProxyUtil$2.r un(ProxyUtil.ja va(Co mpiled Code))
                        at java.security.A ccessController .doPrivileged1( Nativ e Method)
                        at java.security.A ccessController .doPrivileged(A ccess Controller.java (Compiled Code))
                        at com.ibm.rmi.uti l.ProxyUtil.inv okeWithPrivileg e(Pro xyUtil.java(Com piled Code))
                        at com.ibm.CORBA.i iop.ClientDeleg ate.invoke(Clie ntDel egate.java(Comp iled Code))
                        at $Proxy90.invoke (Unknown Source)


                        kllbjbjebe ejhbbhkebef ionelf enjj kf mvg
                        e,m eikb e e3ugbgbfbjhefb f
                        ekeibejb fh eih efvfbehfuefi b kjfjnhevev
                        khefbe fikebffhebfhnem jfjdijkfj knj3vb3hyv fjbedvf
                        efjiefhne fjbefne envfmelfdihvbe ejfgv efkjlv

                        [ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 20] - infrastructure: ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
                        at sun.reflect.Gen eratedMethodAcc essor186.invoke (Unkn own Source)
                        at sun.reflect.Del egatingMethodAc cessorImpl.invo ke(De legatingMethodA ccessorImpl.jav a(Compiled Code))
                        at java.lang.refle ct.Method.invok e(Method.java(C ompil ed Code))
                        at com.ibm.rmi.uti l.ProxyUtil$2.r un(ProxyUtil.ja va(Co mpiled Code))
                        at java.security.A ccessController .doPrivileged1( Nativ e Method)
                        at java.security.A ccessController .doPrivileged(A ccess Controller.java (Compiled Code))
                        at com.ibm.rmi.uti l.ProxyUtil.inv okeWithPrivileg e(Pro xyUtil.java(Com piled Code))
                        at com.ibm.CORBA.i iop.ClientDeleg ate.invoke(Clie ntDel egate.java(Comp iled Code))
                        at $Proxy90.invoke (Unknown Source)
                        nested exception is:
                        infrastructure: RUN_ID_RUNTIME: A runtime exception occurred: javax.transacti on.RollbackExce ption.
                        at sun.reflect.Gen eratedMethodAcc essor186.invoke (Unkn own Source)
                        at sun.reflect.Del egatingMethodAc cessorImpl.invo ke(De legatingMethodA ccessorImpl.jav a(Compiled Code))
                        at java.lang.refle ct.Method.invok e(Method.java(C ompil ed Code))
                        at com.ibm.rmi.uti l.ProxyUtil$2.r un(ProxyUtil.ja va(Co mpiled Code))
                        at java.security.A ccessController .doPrivileged1( Nativ e Method)
                        at java.security.A ccessController .doPrivileged(A ccess Controller.java (Compiled Code))
                        at com.ibm.rmi.uti l.ProxyUtil.inv okeWithPrivileg e(Pro xyUtil.java(Com piled Code))
                        at com.ibm.CORBA.i iop.ClientDeleg ate.invoke(Clie ntDel egate.java(Comp iled Code))
                        at $Proxy90.invoke (Unknown Source)

                        kllbjbjebe ejhbbhkebef ionelf enjj kf mvg
                        e,m eikb e e3ugbgbfbjhefb f
                        ekeibejb fh eih efvfbehfuefi b kjfjnhevev
                        khefbe fikebffhebfhnem jfjdijkfj knj3vb3hyv fjbedvf
                        efjiefhne fjbefne envfmelfdihvbe ejfgv efkjlv

                        [ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 20] - infrastructure: ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
                        at sun.reflect.Gen eratedMethodAcc essor186.invoke (Unkn own Source)
                        at sun.reflect.Del egatingMethodAc cessorImpl.invo ke(De legatingMethodA ccessorImpl.jav a(Compiled Code))
                        at java.lang.refle ct.Method.invok e(Method.java(C ompil ed Code))
                        at com.ibm.rmi.uti l.ProxyUtil$2.r un(ProxyUtil.ja va(Co mpiled Code))
                        at java.security.A ccessController .doPrivileged1( Nativ e Method)
                        at java.security.A ccessController .doPrivileged(A ccess Controller.java (Compiled Code))
                        at com.ibm.rmi.uti l.ProxyUtil.inv okeWithPrivileg e(Pro xyUtil.java(Com piled Code))
                        at com.ibm.CORBA.i iop.ClientDeleg ate.invoke(Clie ntDel egate.java(Comp iled Code))
                        at $Proxy90.invoke (Unknown Source)
                        nested exception is:
                        infrastructure: RUN_ID_RUNTIME: A runtime exception occurred: javax.transacti on.RollbackExce ption.
                        at sun.reflect.Gen eratedMethodAcc essor186.invoke (Unkn own Source)
                        at sun.reflect.Del egatingMethodAc cessorImpl.invo ke(De legatingMethodA ccessorImpl.jav a(Compiled Code))
                        at java.lang.refle ct.Method.invok e(Method.java(C ompil ed Code))
                        at com.ibm.rmi.uti l.ProxyUtil$2.r un(ProxyUtil.ja va(Co mpiled Code))
                        at java.security.A ccessController .doPrivileged1( Nativ e Method)
                        at java.security.A ccessController .doPrivileged(A ccess Controller.java (Compiled Code))
                        at com.ibm.rmi.uti l.ProxyUtil.inv okeWithPrivileg e(Pro xyUtil.java(Com piled Code))
                        at com.ibm.CORBA.i iop.ClientDeleg ate.invoke(Clie ntDel egate.java(Comp iled Code))
                        at $Proxy90.invoke (Unknown Source)
                        [/code]

                        This prints to my terminal:
                        Code:
                        [ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 20] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
                        at sun.reflect.GeneratedMethodAccessor186.invoke(Unkn own Source)
                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java(Compiled Code))
                        at java.lang.reflect.Method.invoke(Method.java(Compil ed Code))
                        at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Co mpiled Code))
                        at java.security.AccessController.doPrivileged1(Nativ e Method)
                        at java.security.AccessController.doPrivileged(Access Controller.java(Compiled Code))
                        at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(Pro xyUtil.java(Compiled Code))
                        at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDel egate.java(Compiled Code))
                        at $Proxy90.invoke(Unknown Source)
                        nested exception is:
                        infrastructure:RUN_ID_RUNTIME: A runtime exception occurred: javax.transaction.RollbackException.
                        at sun.reflect.GeneratedMethodAccessor186.invoke(Unkn own Source)
                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java(Compiled Code))
                        at java.lang.reflect.Method.invoke(Method.java(Compil ed Code))
                        at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Co mpiled Code))
                        at java.security.AccessController.doPrivileged1(Nativ e Method)
                        at java.security.AccessController.doPrivileged(Access Controller.java(Compiled Code))
                        at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(Pro xyUtil.java(Compiled Code))
                        at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDel egate.java(Compiled Code))
                        at $Proxy90.invoke(Unknown Source)
                        
                        [ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 20] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
                        at sun.reflect.GeneratedMethodAccessor186.invoke(Unkn own Source)
                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java(Compiled Code))
                        at java.lang.reflect.Method.invoke(Method.java(Compil ed Code))
                        at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Co mpiled Code))
                        at java.security.AccessController.doPrivileged1(Nativ e Method)
                        at java.security.AccessController.doPrivileged(Access Controller.java(Compiled Code))
                        at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(Pro xyUtil.java(Compiled Code))
                        at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDel egate.java(Compiled Code))
                        at $Proxy90.invoke(Unknown Source)
                        nested exception is:
                        infrastructure:RUN_ID_RUNTIME: A runtime exception occurred: javax.transaction.RollbackException.
                        at sun.reflect.GeneratedMethodAccessor186.invoke(Unkn own Source)
                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java(Compiled Code))
                        at java.lang.reflect.Method.invoke(Method.java(Compil ed Code))
                        at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Co mpiled Code))
                        at java.security.AccessController.doPrivileged1(Nativ e Method)
                        at java.security.AccessController.doPrivileged(Access Controller.java(Compiled Code))
                        at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(Pro xyUtil.java(Compiled Code))
                        at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDel egate.java(Compiled Code))
                        at $Proxy90.invoke(Unknown Source)
                        
                        [ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 20] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
                        at sun.reflect.GeneratedMethodAccessor186.invoke(Unkn own Source)
                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java(Compiled Code))
                        at java.lang.reflect.Method.invoke(Method.java(Compil ed Code))
                        at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Co mpiled Code))
                        at java.security.AccessController.doPrivileged1(Nativ e Method)
                        at java.security.AccessController.doPrivileged(Access Controller.java(Compiled Code))
                        at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(Pro xyUtil.java(Compiled Code))
                        at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDel egate.java(Compiled Code))
                        at $Proxy90.invoke(Unknown Source)
                        nested exception is:
                        infrastructure:RUN_ID_RUNTIME: A runtime exception occurred: javax.transaction.RollbackException.
                        at sun.reflect.GeneratedMethodAccessor186.invoke(Unkn own Source)
                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java(Compiled Code))
                        at java.lang.reflect.Method.invoke(Method.java(Compil ed Code))
                        at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Co mpiled Code))
                        at java.security.AccessController.doPrivileged1(Nativ e Method)
                        at java.security.AccessController.doPrivileged(Access Controller.java(Compiled Code))
                        at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(Pro xyUtil.java(Compiled Code))
                        at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDel egate.java(Compiled Code))
                        at $Proxy90.invoke(Unknown Source)
                        Just change the DATA to your file handle. "LOGFILE".

                        One word of caution.
                        When you slurp, don't do anything else with the data. It takes about as long as assembling an array itself. (If not slightly longer) AND if you then copy the slurped file into an array, you'll have TWO copies on disk.

                        Using it for this should not be a problem, but just be mindful.
                        Feel free to Benchmark!
                        It's your friend.


                        PS- Code tags use square brackets not angle. :)

                        PPS- What do ya know? There's a mod on CPAN for this!!
                        File::Slurp
                        Last edited by Kelicula; Apr 14 '09, 09:31 PM. Reason: Adding File::Slurp link.

                        Comment

                        • Kelicula
                          Recognized Expert New Member
                          • Jul 2007
                          • 176

                          #13
                          I noticed some lines say [ERROR] but you don't want them.
                          Just add the "infrastructure :RUN_ID_RUNTIME " back into the regexe.

                          This should do it:
                          [code=perl]
                          while($file =~ /^(\[ERROR\].*?infrastructu re:RUN_ID_RUNTI ME.*?)\n\n/mgs) {
                          push(@message, $1);
                          }
                          [/code]

                          Comment

                          • Kelicula
                            Recognized Expert New Member
                            • Jul 2007
                            • 176

                            #14
                            That didn't work. :(

                            But this did.

                            [code=perl]
                            while($file =~ /^(\[ERROR\](?-s:.*)infrastruc ture:ID_UNHANDL ED.*?infrastruc ture:RUN_ID_RUN TIME.*?)\n\n/mgs) {
                            push(@message, $1);
                            }
                            [/code]

                            Assuming you want only lines that start with [ERROR] followed by any character EXCEPT a newline, followed by "infrastructure :ID_UNHANDLED", followed by any character INCLUDING a newline, followed by "infrastructure :RUN_ID_RUNTIME ", followed by any character INCLUDING newlines terminating on 2 newlines.

                            WHEEEWW!!

                            OK. That successfully filtered these lines from my test:

                            [ERROR] Undefined

                            [ERROR] jnjbg

                            But MATCHED the ones (I think) you want.

                            Let me know how it comes out!

                            Comment

                            • joeferns79
                              New Member
                              • Sep 2008
                              • 37

                              #15
                              I have no idea what's wrong with my script but even after making it look exactly like you mentioned, it doesn't output anything ...

                              Code:
                              use strict;
                              use warnings;
                              
                              
                              ####################################################################
                              # genreport
                              ####################################################################
                                sub genreport {
                              
                                 my ($logfile, @message); 
                                 
                                 open(LOGFILE, "<$logfile")
                                    or die "Can't open $logfile: $!";
                              
                                 my $file = do { local $/; <LOGFILE> };
                                    
                                 while($file =~ /^(\[ERROR\](?-s:.*)infrastructure:ID_UNHANDLED.*?infrastructure:RUN_ID_RUNTIME.*?)\n\n/mgs) { 
                              push(@message, $1); 
                              } 
                              
                              print "@message";
                              
                              }
                              I even changed the RE to the following and still nothing...

                              Code:
                              use strict;
                              use warnings;
                              
                              
                              ####################################################################
                              # genreport
                              ####################################################################
                                sub genreport {
                              
                                 my ($logfile, @message); 
                                 
                                 open(LOGFILE, "<$logfile")
                                    or die "Can't open $logfile: $!";
                              
                                 my $file = do { local $/; <LOGFILE> };
                                    
                                 while($file =~ /^(\[ERROR\].*?)\n\n/mgs){
                                  push(@message, $1); 
                                } 
                              
                                print "@message";
                              
                              }

                              Comment

                              Working...