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... -
[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_UNHANDLED", i.e. the line ... -
"[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. -
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;
-
}
-
}
-
25 5922
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: -
while ($line = <LOGFILE>) {
-
if ($line =~ /^\[ERROR\](.*?)infrastructure:ID_UNHANDLED:/) {
-
push @message, $line;
-
}
-
elsif ($line =~ /^nested exception is:/) {
-
$line = <LOGFILE>;
-
push @message, $line;
-
last;
-
}
-
}
-
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.
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. -
if ($line =~ /^\[ERROR\](.*?)infrastructure:ID_UNHANDLED:/) {
-
Take out the question mark after the * character. -
if ($line =~ /^\[ERROR\](.*)infrastructure:ID_UNHANDLED:/) {
-
Hope it helps!
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
I changed it to look like this .. -
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?
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: -
-
my @message;
-
-
my $file = <LOGFILE>;
-
-
while($file =~ /^(\[ERROR\].*?infrastructure:ID_UNHANDLED: .*?)\[ERROR\]$/mgs) {
-
push(@message, $1);
-
}
-
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.
I'm still not clear on what it is you need to store in the array from the file.
Kelicula,
I changed it as per your suggestions, but it won't return anything at all... -
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 ... -
[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.
try this: -
OUTTER: while ($line = <LOGFILE>) {
-
if ($line =~ /^\[ERROR\](.*?)infrastructure:ID_UNHANDLED:/) {
-
push @message, $line;
-
while ($line = <LOGFILE>) {
-
redo OUTTER if ($line =~ /^\[ERROR\]/);
-
push @message, $line;
-
}
-
}
-
}
-
@joeferns79
The main thing to notice in my suggestion was this line:
Slurping the whole file into a single var, and then saying... -
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)
This prints to my terminal: -
[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
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: -
while($file =~ /^(\[ERROR\].*?infrastructure:RUN_ID_RUNTIME.*?)\n\n/mgs) {
-
push(@message, $1);
-
}
-
That didn't work. :(
But this did. -
while($file =~ /^(\[ERROR\](?-s:.*)infrastructure:ID_UNHANDLED.*?infrastructure:RUN_ID_RUNTIME.*?)\n\n/mgs) {
-
push(@message, $1);
-
}
-
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!
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 ... -
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... -
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";
-
-
}
-
-
KevinADC,
I tried your suggestion too, and that didn't return anything either ... -
-
use strict;
-
use warnings;
-
-
-
####################################################################
-
# genreport
-
####################################################################
-
sub genreport {
-
-
my ($logfile, $line, @message);
-
-
open(LOGFILE, "<$logfile")
-
or die "Can't open $logfile: $!";
-
-
-
OUTTER: while ($line = <LOGFILE>) {
-
if ($line =~ /^\[ERROR\](.*?)infrastructure:ID_UNHANDLED:/) {
-
push @message, $line;
-
while ($line = <LOGFILE>) {
-
redo OUTTER if ($line =~ /^\[ERROR\]/);
-
push @message, $line;
-
}
-
}
-
}
-
-
print "@message";
-
-
}
-
-
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.
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.
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)
Here's the batch file I call... -
@echo off
-
-
set PERL_HOME=C:\Perl
-
set PATH=%PERL_HOME%\bin;%PATH%
-
-
set script=UAESummary.bat
-
-
-
-
perl UAESummary2.pl %1
-
-
if errorlevel 1 (
-
echo.
-
echo %script%: download failed
-
exit /b 1
-
)
-
I would put the path to the log file under -
my ($logfile, $line, @message);
-
add -
$logfile='PATH\TO\Report.log';
-
No help there ... -
use strict;
-
use warnings;
-
-
-
####################################################################
-
# genreport
-
####################################################################
-
sub genreport {
-
-
my ($logfile, $line, @message);
-
-
$logfile='C:\PerlScripts\CuramApp.log';
-
-
-
-
OUTTER: while ($line = $logfile) {
-
if ($line =~ /^\[ERROR\](.*?)infrastructure:ID_UNHANDLED:/) {
-
push @message, $line;
-
while ($line = $logfile) {
-
redo OUTTER if ($line =~ /^\[ERROR\]/);
-
push @message, $line;
-
}
-
}
-
}
-
-
print "@message";
-
-
}
-
Also, tried ... -
use strict;
-
use warnings;
-
-
-
####################################################################
-
# genreport
-
####################################################################
-
sub genreport {
-
-
my ($logfile, @message);
-
-
$logfile='C:\PerlScripts\CuramApp.log';
-
-
my $file = do { local $/; $logfile };
-
-
while($file =~ /^(\[ERROR\](?-s:.*)infrastructure:ID_UNHANDLED.*?infrastructure:RUN_ID_RUNTIME.*?)\n\n/mgs) {
-
push(@message, $1);
-
}
-
-
print "@message";
-
-
}
-
-
are you ever calling your Sub ? ever ?
Add this above sub genreport {
Sorry for the delay in replying but yes, I am. I am still not seeing any output... -
use strict;
-
-
-
-
####################################################################
-
# genreport
-
####################################################################
-
sub genreport {
-
my ($logfile, $reportfile) = @_;
-
my ($line, @message, @summary, $count, $match, $n);
-
-
open(LOGFILE, "<$logfile")
-
or die "Can't open $logfile: $!";
-
-
open (REPORTFILE, ">$reportfile")
-
or die "Can't open $reportfile: $!";
-
-
-
$count = $match = 0;
-
while ($line = <LOGFILE>) {
-
# chomp $line;
-
if ($line =~ /^(\[ERROR\](?-s:.*)infrastructure:ID_UNHANDLED.*?infrastructure:RUN_ID_RUNTIME.*?)\n\n/mgs) {
-
push @message, $line;
-
$match = 1;
-
next;
-
}
-
-
}
-
for (@message) {
-
print;
-
}
-
-
}
-
-
####################################################################
-
# main
-
####################################################################
-
-
if (@ARGV != 2) {
-
die "usage: UAESummary.pl <logfile> <reportfile>";
-
}
-
-
my ($logfile, $reportfile) = @ARGV;
-
-
genreport($logfile, $reportfile);
-
-
exit 0;
-
-
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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"...
|
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...
|
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 :...
|
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...
|
by: Umesh |
last post by:
Can anyone do it? ARMY1987- what say?
|
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...
|
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...
|
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...
|
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
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
| |