473,748 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Match and Extract everything between 2 words in a file

37 New Member
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_UNHANDL ED", 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
25 5959
KevinADC
4,059 Recognized Expert Specialist
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 Recognized Expert New Member
@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 Recognized Expert New Member
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 Recognized Expert New Member
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
joeferns79
37 New Member
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
joeferns79
37 New Member
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 Recognized Expert New Member
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
joeferns79
37 New Member
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 Recognized Expert New Member
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
joeferns79
37 New Member
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

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

Similar topics

20
5772
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" >>>c = extract(a,b) >>>print c "abcdefghijklmnop"
0
1946
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 should be case-insensitive, but extract should have case preserved.
2
2137
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 : THROUGHOUT I am trying to obtain words between two literal backslashes (\ .. \). I am not able to match words between two literal backslashes using the regxp - re.compile(r'\\*\\').
11
11820
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 that has the word 'event' and the word 'new'. Note that i need lines that has both the words only and not either one of them..
17
2898
by: Umesh | last post by:
Can anyone do it? ARMY1987- what say?
6
4498
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 section? I am doing it reading the contents line by line and setting the flags. But this logic is becoming complex, as i need to match and extract based on certain conditions. for ex:
1
5063
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 array (@names). After I look for the match in this section of the code: if ($value=~/^$names$/), I want to write out only those rows that satisfy the above natch condition. But currently the code I have here writes out everything. How do I get it to...
1
2725
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
5036
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
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8831
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9552
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4877
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.