473,385 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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...
Expand|Select|Wrap|Line Numbers
  1. [ERROR] [06 Apr 2009 09:45:56] [Trace] [WebContainer : 48] - App Number: 0
  2. [ERROR] [06 Apr 2009 09:45:56] [Trace] [WebContainer : 48] - Response for AE Completion No such RID Found
  3. [ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 20] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
  4.     at sun.reflect.GeneratedMethodAccessor186.invoke(Unknown Source)
  5.     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
  6.     at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
  7.     at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Compiled Code))
  8.     at java.security.AccessController.doPrivileged1(Native Method)
  9.     at java.security.AccessController.doPrivileged(AccessController.java(Compiled Code))
  10.     at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(ProxyUtil.java(Compiled Code))
  11.     at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDelegate.java(Compiled Code))
  12.     at $Proxy90.invoke(Unknown Source)
  13. nested exception is:
  14. infrastructure:RUN_ID_RUNTIME: A runtime exception occurred: javax.transaction.RollbackException.
  15.         at sun.reflect.GeneratedMethodAccessor186.invoke(Unknown Source)
  16.     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
  17.     at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
  18.     at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Compiled Code))
  19.     at java.security.AccessController.doPrivileged1(Native Method)
  20.     at java.security.AccessController.doPrivileged(AccessController.java(Compiled Code))
  21.     at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(ProxyUtil.java(Compiled Code))
  22.     at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDelegate.java(Compiled Code))
  23.     at $Proxy90.invoke(Unknown Source)
  24.  
  25. [ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 49] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
  26.     at sun.reflect.GeneratedMethodAccessor186.invoke(Unknown Source)
  27.     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
  28.     at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
  29.     at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Compiled Code))
  30.     at java.security.AccessController.doPrivileged1(Native Method)
  31.  
I want the Perl script to return everything from the file called "App.log" shown above, that matches the line containing "ID_UNHANDLED", i.e. the line ...
Expand|Select|Wrap|Line Numbers
  1. "[ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 20] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator." 
  2. upto the next occurence of the string "[ERROR]" 
  3. i.e. it should include the following ...
  4.  
  5. [ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 20] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
  6. ....
  7. ...
  8. ...
  9. nested exception is:
  10. infrastructure:RUN_ID_RUNTIME: A runtime exception occurred: 
  11. ...
  12. ...
  13. ...
  14. at $Proxy90.invoke(Unknown Source)
  15.  
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.

Expand|Select|Wrap|Line Numbers
  1. while ($line = <LOGFILE>) {
  2.      # chomp $line;
  3.     if ($line =~ /^\[ERROR\](.*?)infrastructure:ID_UNHANDLED:.*$/) {
  4.          push @message, $line;
  5.          $match = 1;
  6.          next;
  7.         }
  8.     if ($match && ($line =~ /^nested exception is:/)) {
  9.         $line = <LOGFILE>;
  10.         push @message, $line;
  11.         $match = 0;
  12.         next;
  13.        }
  14.     }
  15.  
Apr 7 '09 #1
25 5922
KevinADC
4,059 Expert 2GB
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:

Expand|Select|Wrap|Line Numbers
  1. while ($line = <LOGFILE>) {
  2.    if ($line =~ /^\[ERROR\](.*?)infrastructure:ID_UNHANDLED:/) {
  3.       push @message, $line;
  4.    }
  5.    elsif ($line =~ /^nested exception is:/) {
  6.       $line = <LOGFILE>;
  7.       push @message, $line;
  8.       last;
  9.    }
  10. }
  11.  
Apr 7 '09 #2
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.
Apr 8 '09 #3
Kelicula
176 Expert 100+
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.
Expand|Select|Wrap|Line Numbers
  1. if ($line =~ /^\[ERROR\](.*?)infrastructure:ID_UNHANDLED:/) {
  2.  
Take out the question mark after the * character.
Expand|Select|Wrap|Line Numbers
  1. if ($line =~ /^\[ERROR\](.*)infrastructure:ID_UNHANDLED:/) {
  2.  
Hope it helps!
Apr 10 '09 #4
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.transaction.RollbackException.
[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.transaction.RollbackException.

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.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 : 49] - 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
Apr 10 '09 #5
Kelicula
176 Expert 100+
Hum....

I think your answer lies here?
Apr 10 '09 #6
I changed it to look like this ..
Expand|Select|Wrap|Line Numbers
  1. while ($line = <LOGFILE>) {
  2.      # chomp $line;
  3.     if ($line =~ /^\[ERROR\](.*?)infrastructure:ID_UNHANDLED: (.*)\[ERROR\]$/ms) {
  4.          push @message, $line;
  5.          $match = 1;
  6.          next;
  7.         }
  8.       }
  9.  
but now it won't return anything at all. Is the RE incorrect?
Apr 10 '09 #7
Kelicula
176 Expert 100+
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:

Expand|Select|Wrap|Line Numbers
  1.  
  2. my @message;
  3.  
  4. my $file = <LOGFILE>;
  5.  
  6. while($file =~ /^(\[ERROR\].*?infrastructure:ID_UNHANDLED: .*?)\[ERROR\]$/mgs) {
  7. push(@message, $1);
  8. }
  9.  
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...sorry.
Apr 10 '09 #8
KevinADC
4,059 Expert 2GB
I'm still not clear on what it is you need to store in the array from the file.
Apr 10 '09 #9
Kelicula,

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

Expand|Select|Wrap|Line Numbers
  1.   sub genreport {
  2.  
  3.    my ($logfile, $reportfile) = @_;
  4.    my ($file, @message);
  5.  
  6.    open(LOGFILE, "<$logfile")
  7.       or die "Can't open $logfile: $!";
  8.  
  9.    open (REPORTFILE, ">$reportfile")
  10.       or die "Can't open $reportfile: $!";
  11.  
  12.  
  13.    while($file = <LOGFILE>) {
  14.      # chomp $line;
  15.     if ($file =~ /^(\[ERROR\].*?infrastructure:ID_UNHANDLED: .*?)\[ERROR\]$/mgs) {
  16.          push @message, $1;
  17.  
  18.         }
  19.  
  20.     }
  21. }
  22.  
  23.  

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

Expand|Select|Wrap|Line Numbers
  1. [ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 20] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator. 
  2.     at sun.reflect.GeneratedMethodAccessor186.invoke(Unknown Source) 
  3.     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code)) 
  4.     at java.lang.reflect.Method.invoke(Method.java(Compiled Code)) 
  5.     at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Compiled Code)) 
  6.     at java.security.AccessController.doPrivileged1(Native Method) 
  7.     at java.security.AccessController.doPrivileged(AccessController.java(Compiled Code)) 
  8.     at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(ProxyUtil.java(Compiled Code)) 
  9.     at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDelegate.java(Compiled Code)) 
  10.     at $Proxy90.invoke(Unknown Source) 
  11. nested exception is: 
  12. infrastructure:RUN_ID_RUNTIME: A runtime exception occurred: javax.transaction.RollbackException. 
  13.         at sun.reflect.GeneratedMethodAccessor186.invoke(Unknown Source) 
  14.     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code)) 
  15.     at java.lang.reflect.Method.invoke(Method.java(Compiled Code)) 
  16.     at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Compiled Code)) 
  17.     at java.security.AccessController.doPrivileged1(Native Method) 
  18.     at java.security.AccessController.doPrivileged(AccessController.java(Compiled Code)) 
  19.     at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(ProxyUtil.java(Compiled Code)) 
  20.     at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDelegate.java(Compiled Code)) 
  21.     at $Proxy90.invoke(Unknown Source) 
  22.  
The above belongs to 1 un-handled exception. But the log file contains many un-handled exceptions, so I want all these returned.
Apr 14 '09 #10
KevinADC
4,059 Expert 2GB
try this:

Expand|Select|Wrap|Line Numbers
  1. OUTTER: while ($line = <LOGFILE>) {
  2.    if ($line =~ /^\[ERROR\](.*?)infrastructure:ID_UNHANDLED:/) {
  3.       push @message, $line;
  4.       while ($line = <LOGFILE>) {
  5.          redo OUTTER if ($line =~ /^\[ERROR\]/);
  6.          push @message, $line;
  7.       }
  8.    }
  9. }
  10.  
Apr 14 '09 #11
Kelicula
176 Expert 100+
@joeferns79

The main thing to notice in my suggestion was this line:
Expand|Select|Wrap|Line Numbers
  1. my $file = <LOGFILE>;
  2.  
Slurping the whole file into a single var, and then saying...

Expand|Select|Wrap|Line Numbers
  1. while(match){
  2. push $message, $1;
  3. }
  4.  
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)

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3.  
  4. my @message;
  5.  
  6. my $file = do { local $/; <DATA> }; # slurp file, undefined $/ only for this scope.
  7.  
  8. # while there is a match, populate message array with match.
  9. while($file =~ /^(\[ERROR\].*?)\n\n/mgs) {
  10. push(@message, $1);
  11.  
  12. }
  13.  
  14. $" = "\n\n"; # Added this just so I could see matches in my terminal instead of one long string.
  15.  
  16. print "@message";
  17.  
  18.  
  19. __DATA__
  20.  
  21.  
  22. kllbjbjebe ejhbbhkebef ionelf enjj kf mvg
  23. e,m eikb e e3ugbgbfbjhefb f
  24. ekeibejb fh eih efvfbehfuefi b kjfjnhevev
  25. khefbe fikebffhebfhnemjfjdijkfj knj3vb3hyv fjbedvf
  26. efjiefhne fjbefne envfmelfdihvbe ejfgv efkjlv
  27.  
  28.  
  29. [ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 20] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
  30. at sun.reflect.GeneratedMethodAccessor186.invoke(Unkn own Source)
  31. at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java(Compiled Code))
  32. at java.lang.reflect.Method.invoke(Method.java(Compil ed Code))
  33. at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Co mpiled Code))
  34. at java.security.AccessController.doPrivileged1(Nativ e Method)
  35. at java.security.AccessController.doPrivileged(Access Controller.java(Compiled Code))
  36. at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(Pro xyUtil.java(Compiled Code))
  37. at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDel egate.java(Compiled Code))
  38. at $Proxy90.invoke(Unknown Source)
  39. nested exception is:
  40. infrastructure:RUN_ID_RUNTIME: A runtime exception occurred: javax.transaction.RollbackException.
  41. at sun.reflect.GeneratedMethodAccessor186.invoke(Unkn own Source)
  42. at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java(Compiled Code))
  43. at java.lang.reflect.Method.invoke(Method.java(Compil ed Code))
  44. at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Co mpiled Code))
  45. at java.security.AccessController.doPrivileged1(Nativ e Method)
  46. at java.security.AccessController.doPrivileged(Access Controller.java(Compiled Code))
  47. at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(Pro xyUtil.java(Compiled Code))
  48. at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDel egate.java(Compiled Code))
  49. at $Proxy90.invoke(Unknown Source)
  50.  
  51.  
  52. kllbjbjebe ejhbbhkebef ionelf enjj kf mvg
  53. e,m eikb e e3ugbgbfbjhefb f
  54. ekeibejb fh eih efvfbehfuefi b kjfjnhevev
  55. khefbe fikebffhebfhnemjfjdijkfj knj3vb3hyv fjbedvf
  56. efjiefhne fjbefne envfmelfdihvbe ejfgv efkjlv
  57.  
  58. [ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 20] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
  59. at sun.reflect.GeneratedMethodAccessor186.invoke(Unkn own Source)
  60. at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java(Compiled Code))
  61. at java.lang.reflect.Method.invoke(Method.java(Compil ed Code))
  62. at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Co mpiled Code))
  63. at java.security.AccessController.doPrivileged1(Nativ e Method)
  64. at java.security.AccessController.doPrivileged(Access Controller.java(Compiled Code))
  65. at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(Pro xyUtil.java(Compiled Code))
  66. at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDel egate.java(Compiled Code))
  67. at $Proxy90.invoke(Unknown Source)
  68. nested exception is:
  69. infrastructure:RUN_ID_RUNTIME: A runtime exception occurred: javax.transaction.RollbackException.
  70. at sun.reflect.GeneratedMethodAccessor186.invoke(Unkn own Source)
  71. at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java(Compiled Code))
  72. at java.lang.reflect.Method.invoke(Method.java(Compil ed Code))
  73. at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Co mpiled Code))
  74. at java.security.AccessController.doPrivileged1(Nativ e Method)
  75. at java.security.AccessController.doPrivileged(Access Controller.java(Compiled Code))
  76. at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(Pro xyUtil.java(Compiled Code))
  77. at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDel egate.java(Compiled Code))
  78. at $Proxy90.invoke(Unknown Source)
  79.  
  80. kllbjbjebe ejhbbhkebef ionelf enjj kf mvg
  81. e,m eikb e e3ugbgbfbjhefb f
  82. ekeibejb fh eih efvfbehfuefi b kjfjnhevev
  83. khefbe fikebffhebfhnemjfjdijkfj knj3vb3hyv fjbedvf
  84. efjiefhne fjbefne envfmelfdihvbe ejfgv efkjlv
  85.  
  86. [ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 20] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
  87. at sun.reflect.GeneratedMethodAccessor186.invoke(Unkn own Source)
  88. at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java(Compiled Code))
  89. at java.lang.reflect.Method.invoke(Method.java(Compil ed Code))
  90. at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Co mpiled Code))
  91. at java.security.AccessController.doPrivileged1(Nativ e Method)
  92. at java.security.AccessController.doPrivileged(Access Controller.java(Compiled Code))
  93. at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(Pro xyUtil.java(Compiled Code))
  94. at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDel egate.java(Compiled Code))
  95. at $Proxy90.invoke(Unknown Source)
  96. nested exception is:
  97. infrastructure:RUN_ID_RUNTIME: A runtime exception occurred: javax.transaction.RollbackException.
  98. at sun.reflect.GeneratedMethodAccessor186.invoke(Unkn own Source)
  99. at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java(Compiled Code))
  100. at java.lang.reflect.Method.invoke(Method.java(Compil ed Code))
  101. at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Co mpiled Code))
  102. at java.security.AccessController.doPrivileged1(Nativ e Method)
  103. at java.security.AccessController.doPrivileged(Access Controller.java(Compiled Code))
  104. at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(Pro xyUtil.java(Compiled Code))
  105. at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDel egate.java(Compiled Code))
  106. at $Proxy90.invoke(Unknown Source)
  107.  
This prints to my terminal:
Expand|Select|Wrap|Line Numbers
  1. [ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 20] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
  2. at sun.reflect.GeneratedMethodAccessor186.invoke(Unkn own Source)
  3. at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java(Compiled Code))
  4. at java.lang.reflect.Method.invoke(Method.java(Compil ed Code))
  5. at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Co mpiled Code))
  6. at java.security.AccessController.doPrivileged1(Nativ e Method)
  7. at java.security.AccessController.doPrivileged(Access Controller.java(Compiled Code))
  8. at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(Pro xyUtil.java(Compiled Code))
  9. at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDel egate.java(Compiled Code))
  10. at $Proxy90.invoke(Unknown Source)
  11. nested exception is:
  12. infrastructure:RUN_ID_RUNTIME: A runtime exception occurred: javax.transaction.RollbackException.
  13. at sun.reflect.GeneratedMethodAccessor186.invoke(Unkn own Source)
  14. at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java(Compiled Code))
  15. at java.lang.reflect.Method.invoke(Method.java(Compil ed Code))
  16. at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Co mpiled Code))
  17. at java.security.AccessController.doPrivileged1(Nativ e Method)
  18. at java.security.AccessController.doPrivileged(Access Controller.java(Compiled Code))
  19. at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(Pro xyUtil.java(Compiled Code))
  20. at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDel egate.java(Compiled Code))
  21. at $Proxy90.invoke(Unknown Source)
  22.  
  23. [ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 20] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
  24. at sun.reflect.GeneratedMethodAccessor186.invoke(Unkn own Source)
  25. at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java(Compiled Code))
  26. at java.lang.reflect.Method.invoke(Method.java(Compil ed Code))
  27. at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Co mpiled Code))
  28. at java.security.AccessController.doPrivileged1(Nativ e Method)
  29. at java.security.AccessController.doPrivileged(Access Controller.java(Compiled Code))
  30. at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(Pro xyUtil.java(Compiled Code))
  31. at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDel egate.java(Compiled Code))
  32. at $Proxy90.invoke(Unknown Source)
  33. nested exception is:
  34. infrastructure:RUN_ID_RUNTIME: A runtime exception occurred: javax.transaction.RollbackException.
  35. at sun.reflect.GeneratedMethodAccessor186.invoke(Unkn own Source)
  36. at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java(Compiled Code))
  37. at java.lang.reflect.Method.invoke(Method.java(Compil ed Code))
  38. at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Co mpiled Code))
  39. at java.security.AccessController.doPrivileged1(Nativ e Method)
  40. at java.security.AccessController.doPrivileged(Access Controller.java(Compiled Code))
  41. at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(Pro xyUtil.java(Compiled Code))
  42. at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDel egate.java(Compiled Code))
  43. at $Proxy90.invoke(Unknown Source)
  44.  
  45. [ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 20] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
  46. at sun.reflect.GeneratedMethodAccessor186.invoke(Unkn own Source)
  47. at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java(Compiled Code))
  48. at java.lang.reflect.Method.invoke(Method.java(Compil ed Code))
  49. at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Co mpiled Code))
  50. at java.security.AccessController.doPrivileged1(Nativ e Method)
  51. at java.security.AccessController.doPrivileged(Access Controller.java(Compiled Code))
  52. at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(Pro xyUtil.java(Compiled Code))
  53. at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDel egate.java(Compiled Code))
  54. at $Proxy90.invoke(Unknown Source)
  55. nested exception is:
  56. infrastructure:RUN_ID_RUNTIME: A runtime exception occurred: javax.transaction.RollbackException.
  57. at sun.reflect.GeneratedMethodAccessor186.invoke(Unkn own Source)
  58. at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java(Compiled Code))
  59. at java.lang.reflect.Method.invoke(Method.java(Compil ed Code))
  60. at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Co mpiled Code))
  61. at java.security.AccessController.doPrivileged1(Nativ e Method)
  62. at java.security.AccessController.doPrivileged(Access Controller.java(Compiled Code))
  63. at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(Pro xyUtil.java(Compiled Code))
  64. at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDel egate.java(Compiled Code))
  65. at $Proxy90.invoke(Unknown Source)
  66.  
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
Apr 14 '09 #12
Kelicula
176 Expert 100+
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:
Expand|Select|Wrap|Line Numbers
  1. while($file =~ /^(\[ERROR\].*?infrastructure:RUN_ID_RUNTIME.*?)\n\n/mgs) {
  2. push(@message, $1);
  3. }
  4.  
Apr 14 '09 #13
Kelicula
176 Expert 100+
That didn't work. :(

But this did.

Expand|Select|Wrap|Line Numbers
  1. while($file =~ /^(\[ERROR\](?-s:.*)infrastructure:ID_UNHANDLED.*?infrastructure:RUN_ID_RUNTIME.*?)\n\n/mgs) {
  2. push(@message, $1);
  3. }
  4.  
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!
Apr 14 '09 #14
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 ...

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3.  
  4.  
  5. ####################################################################
  6. # genreport
  7. ####################################################################
  8.   sub genreport {
  9.  
  10.    my ($logfile, @message); 
  11.  
  12.    open(LOGFILE, "<$logfile")
  13.       or die "Can't open $logfile: $!";
  14.  
  15.    my $file = do { local $/; <LOGFILE> };
  16.  
  17.    while($file =~ /^(\[ERROR\](?-s:.*)infrastructure:ID_UNHANDLED.*?infrastructure:RUN_ID_RUNTIME.*?)\n\n/mgs) { 
  18. push(@message, $1); 
  19.  
  20. print "@message";
  21.  
  22. }
  23.  
I even changed the RE to the following and still nothing...

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3.  
  4.  
  5. ####################################################################
  6. # genreport
  7. ####################################################################
  8.   sub genreport {
  9.  
  10.    my ($logfile, @message); 
  11.  
  12.    open(LOGFILE, "<$logfile")
  13.       or die "Can't open $logfile: $!";
  14.  
  15.    my $file = do { local $/; <LOGFILE> };
  16.  
  17.    while($file =~ /^(\[ERROR\].*?)\n\n/mgs){
  18.     push(@message, $1); 
  19.   } 
  20.  
  21.   print "@message";
  22.  
  23. }
  24.  
  25.  
Apr 20 '09 #15
KevinADC,
I tried your suggestion too, and that didn't return anything either ...

Expand|Select|Wrap|Line Numbers
  1.  
  2. use strict;
  3. use warnings;
  4.  
  5.  
  6. ####################################################################
  7. # genreport
  8. ####################################################################
  9.   sub genreport {
  10.  
  11.    my ($logfile, $line, @message); 
  12.  
  13.    open(LOGFILE, "<$logfile")
  14.       or die "Can't open $logfile: $!";
  15.  
  16.  
  17. OUTTER: while ($line = <LOGFILE>) { 
  18.          if ($line =~ /^\[ERROR\](.*?)infrastructure:ID_UNHANDLED:/) { 
  19.            push @message, $line; 
  20.          while ($line = <LOGFILE>) { 
  21.           redo OUTTER if ($line =~ /^\[ERROR\]/); 
  22.          push @message, $line; 
  23.       } 
  24.    } 
  25.  
  26. print "@message";
  27.  
  28. }
  29.  
  30.  
Apr 20 '09 #16
Kelicula
176 Expert 100+
Hummm....
How are you calling on genreport?
What exactly do you pass to it?
Is it in the current package, or a separate file?

Very strange.

Have you tried KevinADC's code?
It looks like it works too. (using too objectively..:)

I swear my code worked in Komodo with Perl 5.10 on Windows.

Of course I didn't have the exact same logfile to scan.
Apr 20 '09 #17
I am calling it through a batch file in a command prompt in Windows and pass the name of the log file, i.e.

UAESummary.bat AppLog.txt > Report.log


Yes, I tried KevinADC's code too, to no avail.
Apr 20 '09 #18
Icecrack
174 Expert 100+
he means how are you running the Perl script
if the script is being run by that Batch file, may you post the code to that batch file here.
in [CODE*] [/CODE*] Tags (take out the * for code tags to work)
Apr 21 '09 #19
Here's the batch file I call...
Expand|Select|Wrap|Line Numbers
  1. @echo off
  2.  
  3. set PERL_HOME=C:\Perl
  4. set PATH=%PERL_HOME%\bin;%PATH%
  5.  
  6. set script=UAESummary.bat
  7.  
  8.  
  9.  
  10. perl UAESummary2.pl %1
  11.  
  12. if errorlevel 1 (
  13.    echo.
  14.    echo %script%: download failed
  15.    exit /b 1
  16. )
  17.  
Apr 21 '09 #20
Icecrack
174 Expert 100+
I would put the path to the log file under
Expand|Select|Wrap|Line Numbers
  1. my ($logfile, $line, @message);
  2.  
add
Expand|Select|Wrap|Line Numbers
  1. $logfile='PATH\TO\Report.log';
  2.  
Apr 22 '09 #21
No help there ...

Expand|Select|Wrap|Line Numbers
  1. use strict; 
  2. use warnings; 
  3.  
  4.  
  5. #################################################################### 
  6. # genreport 
  7. #################################################################### 
  8.   sub genreport { 
  9.  
  10.    my ($logfile, $line, @message);  
  11.  
  12.    $logfile='C:\PerlScripts\CuramApp.log';
  13.  
  14.  
  15.  
  16. OUTTER: while ($line = $logfile) {  
  17.          if ($line =~ /^\[ERROR\](.*?)infrastructure:ID_UNHANDLED:/) {  
  18.            push @message, $line;  
  19.          while ($line = $logfile) {  
  20.           redo OUTTER if ($line =~ /^\[ERROR\]/);  
  21.          push @message, $line;  
  22.       }  
  23.    }  
  24. }  
  25.  
  26. print "@message"; 
  27.  
  28.  
Also, tried ...

Expand|Select|Wrap|Line Numbers
  1. use strict; 
  2. use warnings; 
  3.  
  4.  
  5. #################################################################### 
  6. # genreport 
  7. #################################################################### 
  8.   sub genreport { 
  9.  
  10.    my ($logfile, @message);  
  11.  
  12.    $logfile='C:\PerlScripts\CuramApp.log';
  13.  
  14.    my $file = do { local $/; $logfile }; 
  15.  
  16.    while($file =~ /^(\[ERROR\](?-s:.*)infrastructure:ID_UNHANDLED.*?infrastructure:RUN_ID_RUNTIME.*?)\n\n/mgs) {  
  17. push(@message, $1);  
  18. }  
  19.  
  20. print "@message"; 
  21.  
  22.  
  23.  
Apr 22 '09 #22
Icecrack
174 Expert 100+
are you ever calling your Sub ? ever ?


Add this above sub genreport {
Expand|Select|Wrap|Line Numbers
  1. &genreport;
Apr 22 '09 #23
Sorry for the delay in replying but yes, I am. I am still not seeing any output...

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2.  
  3.  
  4.  
  5. ####################################################################
  6. # genreport
  7. ####################################################################
  8.   sub genreport {
  9.    my ($logfile, $reportfile) = @_;
  10.    my ($line, @message, @summary, $count, $match, $n);
  11.  
  12.    open(LOGFILE, "<$logfile")
  13.       or die "Can't open $logfile: $!";
  14.  
  15.    open (REPORTFILE, ">$reportfile")
  16.       or die "Can't open $reportfile: $!";
  17.  
  18.  
  19.    $count = $match = 0;
  20.    while ($line = <LOGFILE>) {
  21.      # chomp $line;
  22.     if ($line =~ /^(\[ERROR\](?-s:.*)infrastructure:ID_UNHANDLED.*?infrastructure:RUN_ID_RUNTIME.*?)\n\n/mgs) {
  23.          push @message, $line;
  24.          $match = 1;
  25.          next;
  26.         }
  27.  
  28.     }
  29.    for (@message) {
  30.    print;
  31.  }
  32.  
  33. }
  34.  
  35. ####################################################################
  36. # main
  37. ####################################################################
  38.  
  39. if (@ARGV != 2) {
  40.    die "usage: UAESummary.pl <logfile> <reportfile>";
  41. }
  42.  
  43. my ($logfile, $reportfile) = @ARGV;
  44.  
  45. genreport($logfile, $reportfile);
  46.  
  47. exit 0;
  48.  
  49.  
May 4 '09 #24
Icecrack
174 Expert 100+
sorry for the delay on my end i have been testing this for weeks now, and just found the answer but first i need to know how your logs are set out is it 1 big single line or is it a multi-lined?
past a log file here as a file attachment
May 15 '09 #25
Icecrack, I was going through the forum and I noticed that you had posted a reply. I know it's like 2 months since you replied and I am not sure if you'll get this, but yes, it's a multi-line log.
Jul 22 '09 #26

Sign in to post your reply or Sign up for a free account.

Similar topics

20
by: Ravi | last post by:
Hi, I have about 200GB of data that I need to go through and extract the common first part of a line. Something like this. >>>a = "abcdefghijklmnopqrstuvwxyz" >>>b = "abcdefghijklmnopBHLHT"...
0
by: Follower | last post by:
Hi, I am working on a function to return extracts from a text document with a specific phrase highlighted (i.e. display the context of the matched phrase). The requirements are: * Match...
2
by: cricfan | last post by:
I'm parsing a text file to extract word definitions. For example the input text file contains the following content: di.va.gate \'di_--v*-.ga_-t\ vb pas.sim \'pas-*m\ adv : here and there :...
11
by: elrondrules | last post by:
Hi Am pretty new to python and hence this question.. I have file with an output of a process. I need to search this file one line at a time and my pattern is that I am looking for the lines...
17
by: Umesh | last post by:
Can anyone do it? ARMY1987- what say?
6
by: pramodkh | last post by:
Hi All Today only i joined this group. need ur help. Here goes my question: Is there any simple way to match for a particular pattern ( with start and end delimitters) and extract the matched...
1
by: manishabh77 | last post by:
I will be obliged if anybody can help me with this problem: I am trying to extract data from an excel sheet that matches IDs given in column 4 of the excel sheet.I have stored those query IDs in an...
1
by: Edwin.Madari | last post by:
from each line separate out url and request parts. split the request into key-value pairs, use urllib to unquote key-value pairs......as show below... import urllib line = "GET...
3
by: dmalhotr2001 | last post by:
Hi, For string extraction function in vb, if I feed in a paragraph, how do I extract the first sentence of that paragraph. Thanks :D
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.