Extract lines from a file | Member | | Join Date: Sep 2008
Posts: 35
| |
I have this log ... -
[ERROR] [02 Sep 2009 11:33:17] [Trace] [WebContainer : 54] - infrastructure:ID_UNHANDLED: An un-handled server exception occu
-
rred. Please contact your administrator.
-
at .util.internal.HandleException.getRemoteException(HandleException.java(Compiled Code))
-
at .util.internal.HandleException.getRemoteException(HandleException.java(Compiled Co
-
nested exception is:
-
infrastructure:RUN_ID_RUNTIME: A runtime exception occurred: javax.transaction.RollbackException.
-
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.ja
-
at .interfaces.Search_TH.invokeStub
-
nested exception is:
-
javax.transaction.RollbackException
-
at com.ibm.ws.Transaction.JTA.TransactionImpl.stage3CommitProcessing(TransactionImpl.java(Compiled Code))
-
at com.ibm.ws.Transaction.JTA.TransactionImpl.processCommit(TransactionImpl.java(Compiled Code))
-
at com.ibm.ws.Transaction.JTA.TransactionImpl.commit(TransactionImpl.java(Compiled Code))
-
at com.ibm.ws.Transaction.JTA.TranManagerImpl.commit(TranManagerImpl.java(Compiled Code))
-
at com.ibm.ws.Transaction.JTA.TranManagerSet.commit(TranManagerSet.java(Compiled Code))
-
at com.ibm.ws.Transaction.JTA.UserTransactionImpl.commit(UserTransactionImpl.java(Compiled Code))
-
at com.ibm.ejs.container.UserTransactionWrapper.commit(UserTransactionWrapper.java(Compiled Code))
-
at .util.transaction.ResourcesJTA.M-T00000(ResourcesJTA.java(Compiled Code))
-
at .util.transaction.TransactionInfo.commit(TransactionInfo.java(Compiled C
-
-
[ERROR] [02 Sep 2009 11:33:18] [Trace.Tools] [WebContainer : 61] - infrastructure:RUN_ID_RECORD_NOT_FOUND: Record not found.
-
[ERROR] [02 Sep 2009 11:33:18] [Trace.Tools] [WebContainer : 61] - infrastructure:RUN_ID_RECORD_NOT_FOUND: Record not found.
-
I need to input it into a perl script that takes 2 arguments, an input file, i.e. the log above and an output file, that will contain the output,
eg. Rollback.pl input.log report.log
First, I need to search for the string "UNHANDLED" and within that stack trace, I need to find the string "RollbackException". If the "RollbackException" string is found, I need to find the "_TH" string, that's within "RollbackException".
Finally I need to print the date that's on the "UNHANDLED" line and the line that contains the "_TH" string.
The "UNHANDLED" string could contain more than 1 "RollbackException" string but I need to find just the 1st instance of "RollbackException" and then within that find the first instance of "_TH".
The delimiters could be [ERROR].
The date and "_TH" string should then be output to the "report.log" file.
|  | Site Moderator | | Join Date: May 2007 Location: New Hampshire
Posts: 2,572
| | | re: Extract lines from a file Quote:
Originally Posted by joeferns79 I have this log ... -
[ERROR] [02 Sep 2009 11:33:17] [Trace] [WebContainer : 54] - infrastructure:ID_UNHANDLED: An un-handled server exception occu
-
rred. Please contact your administrator.
-
at .util.internal.HandleException.getRemoteException(HandleException.java(Compiled Code))
-
at .util.internal.HandleException.getRemoteException(HandleException.java(Compiled Co
-
nested exception is:
-
infrastructure:RUN_ID_RUNTIME: A runtime exception occurred: javax.transaction.RollbackException.
-
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.ja
-
at .interfaces.Search_TH.invokeStub
-
nested exception is:
-
javax.transaction.RollbackException
-
at com.ibm.ws.Transaction.JTA.TransactionImpl.stage3CommitProcessing(TransactionImpl.java(Compiled Code))
-
at com.ibm.ws.Transaction.JTA.TransactionImpl.processCommit(TransactionImpl.java(Compiled Code))
-
at com.ibm.ws.Transaction.JTA.TransactionImpl.commit(TransactionImpl.java(Compiled Code))
-
at com.ibm.ws.Transaction.JTA.TranManagerImpl.commit(TranManagerImpl.java(Compiled Code))
-
at com.ibm.ws.Transaction.JTA.TranManagerSet.commit(TranManagerSet.java(Compiled Code))
-
at com.ibm.ws.Transaction.JTA.UserTransactionImpl.commit(UserTransactionImpl.java(Compiled Code))
-
at com.ibm.ejs.container.UserTransactionWrapper.commit(UserTransactionWrapper.java(Compiled Code))
-
at .util.transaction.ResourcesJTA.M-T00000(ResourcesJTA.java(Compiled Code))
-
at .util.transaction.TransactionInfo.commit(TransactionInfo.java(Compiled C
-
-
[ERROR] [02 Sep 2009 11:33:18] [Trace.Tools] [WebContainer : 61] - infrastructure:RUN_ID_RECORD_NOT_FOUND: Record not found.
-
[ERROR] [02 Sep 2009 11:33:18] [Trace.Tools] [WebContainer : 61] - infrastructure:RUN_ID_RECORD_NOT_FOUND: Record not found.
-
I need to input it into a perl script that takes 2 arguments, an input file, i.e. the log above and an output file, that will contain the output,
eg. Rollback.pl input.log report.log
First, I need to search for the string "UNHANDLED" and within that stack trace, I need to find the string "RollbackException". If the "RollbackException" string is found, I need to find the "_TH" string, that's within "RollbackException".
Finally I need to print the date that's on the "UNHANDLED" line and the line that contains the "_TH" string.
The "UNHANDLED" string could contain more than 1 "RollbackException" string but I need to find just the 1st instance of "RollbackException" and then within that find the first instance of "_TH".
The delimiters could be [ERROR].
The date and "_TH" string should then be output to the "report.log" file. Ok, so what have you tried thus far? Please show your code.
Regards,
Jeff
| | Member | | Join Date: Sep 2008
Posts: 35
| | | re: Extract lines from a file -
-
use strict;
-
-
-
####################################################################
-
# constants
-
####################################################################
-
-
use constant COUNT => 0;
-
use constant MAX => 1;
-
use constant MIN => 2;
-
use constant TOTAL => 3;
-
use constant AVERAGE => 4;
-
use constant FCOUNT => 5;
-
use constant FMAX => 6;
-
use constant FMIN => 7;
-
use constant FTOTAL => 8;
-
use constant FAVERAGE => 9;
-
-
####################################################################
-
# genreport
-
####################################################################
-
-
sub genreport {
-
my ($logfile, $reportfile) = @_;
-
my ($line, $elapsed, $facade, %calls);
-
my (@fields, $count, $min, $max, $total, $average,$fcount,$fmin,$fmax,$ftotal,$faverage);
-
my (@list, $totalcalls);
-
my ($falseflag);
-
my ($statdate,$server);
-
my ($starttime,$error,$first);
-
open(LOGFILE, "<$logfile")
-
or die "Can't open $logfile: $!";
-
-
open(REPORTFILE, ">$reportfile")
-
or die "Can't open $reportfile: $!";
-
-
$totalcalls = 0;
-
while ($line = <LOGFILE>) {
-
chomp $line;
-
$falseflag= 0;
-
$statdate = substr($line,9,11);
-
$starttime = substr($line,21,8);
-
if($line =~(/UNHANDLED/))
-
{
-
while ($line =<LOGFILE>){
-
if($line =~(/RollbackException/))
-
{
-
$falseflag = 1;
-
while ($line =<LOGFILE>){
-
if($line =~(/_TH/)) {
-
$line = substr($line,3,length($line));
-
printf "%s, %s,%s\n",$statdate,$starttime,$line;
-
last;
-
}
-
}
-
}
-
}
-
}
-
}
-
}
-
####################################################################
-
# main
-
####################################################################
-
-
if (@ARGV != 2) {
-
die "usage: servercalls.pl <logfile> <reportfile>";
-
}
-
-
my ($logfile, $reportfile) = @ARGV;
-
-
genreport($logfile, $reportfile);
-
-
|  | Expert | | Join Date: Jan 2007 Location: Southern California USA
Posts: 4,091
| | | re: Extract lines from a file
How come you have not added the filehandle name where you want to redirect output to a file like Jeff showed you?
| | Member | | Join Date: Sep 2008
Posts: 35
| | | re: Extract lines from a file
Sorry, the one I made a change to was another script. Here's this one with the change.... -
use strict;
-
-
-
####################################################################
-
# constants
-
####################################################################
-
-
use constant COUNT => 0;
-
use constant MAX => 1;
-
use constant MIN => 2;
-
use constant TOTAL => 3;
-
use constant AVERAGE => 4;
-
use constant FCOUNT => 5;
-
use constant FMAX => 6;
-
use constant FMIN => 7;
-
use constant FTOTAL => 8;
-
use constant FAVERAGE => 9;
-
-
####################################################################
-
# genreport
-
####################################################################
-
-
sub genreport {
-
my ($logfile, $reportfile) = @_;
-
my ($line, $elapsed, $facade, %calls);
-
my (@fields, $count, $min, $max, $total, $average,$fcount,$fmin,$fmax,$ftotal,$faverage);
-
my (@list, $totalcalls);
-
my ($falseflag);
-
my ($statdate,$server);
-
my ($starttime,$error,$first);
-
open(LOGFILE, "<$logfile")
-
or die "Can't open $logfile: $!";
-
-
open(REPORTFILE, ">$reportfile")
-
or die "Can't open $reportfile: $!";
-
-
$totalcalls = 0;
-
while ($line = <LOGFILE>) {
-
chomp $line;
-
$falseflag= 0;
-
$statdate = substr($line,9,11);
-
$starttime = substr($line,21,8);
-
if($line =~(/UNHANDLED/))
-
{
-
while ($line =<LOGFILE>){
-
if($line =~(/RollbackException/))
-
{
-
$falseflag = 1;
-
while ($line =<LOGFILE>){
-
if($line =~(/_TH/)) {
-
$line = substr($line,3,length($line));
-
printf REPORTFILE "%s, %s,%s\n",$statdate,$starttime,$line;
-
last;
-
}
-
}
-
}
-
}
-
}
-
}
-
}
-
####################################################################
-
# main
-
####################################################################
-
-
if (@ARGV != 2) {
-
die "usage: servercalls.pl <logfile> <reportfile>";
-
}
-
-
my ($logfile, $reportfile) = @ARGV;
-
-
genreport($logfile, $reportfile);
-
-
| | Member | | Join Date: Sep 2008
Posts: 35
| | | re: Extract lines from a file
Somehow, the line that's supposed to be printed just once is getting repeated 4 times, since the line with the "_TH" string is present in 4 locations under the stack trace.
i.e. the input log looks like this... -
-
[ERROR] [02 Sep 2009 11:33:17] [Trace] [WebContainer : 54] - infrastructure:ID_UNHANDLED: An un-handled server exception occu
-
rred. Please contact your administrator.
-
at .util.internal.HandleException.getRemoteException(HandleException.java(Compiled Code))
-
at .util.internal.HandleException.getRemoteException(HandleException.java(Compiled Co
-
at .interfaces.Search_TH.invokeStub
-
nested exception is:
-
infrastructure:RUN_ID_RUNTIME: A runtime exception occurred: javax.transaction.RollbackException.
-
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.ja
-
at .interfaces.Search_TH.invokeStub
-
nested exception is:
-
javax.transaction.RollbackException
-
at com.ibm.ws.Transaction.JTA.TransactionImpl.stage3CommitProcessing(TransactionImpl.java(Compiled Code))
-
at com.ibm.ws.Transaction.JTA.TransactionImpl.processCommit(TransactionImpl.java(Compiled Code))
-
at com.ibm.ws.Transaction.JTA.TransactionImpl.commit(TransactionImpl.java(Compiled Code))
-
at com.ibm.ws.Transaction.JTA.TranManagerImpl.commit(TranManagerImpl.java(Compiled Code))
-
at com.ibm.ws.Transaction.JTA.TranManagerSet.commit(TranManagerSet.java(Compiled Code))
-
at com.ibm.ws.Transaction.JTA.UserTransactionImpl.commit(UserTransactionImpl.java(Compiled Code))
-
at com.ibm.ejs.container.UserTransactionWrapper.commit(UserTransactionWrapper.java(Compiled Code))
-
at .util.transaction.ResourcesJTA.M-T00000(ResourcesJTA.java(Compiled Code))
-
at .util.transaction.TransactionInfo.commit(TransactionInfo.java(Compiled C
-
at .interfaces.Search_TH.invokeStub
-
nested exception is:
-
javax.transaction.RollbackException
-
at com.ibm.ws.Transaction.JTA.TransactionImpl.stage3CommitProcessing(TransactionImpl.java(Compiled Code))
-
at com.ibm.ws.Transaction.JTA.TransactionImpl.processCommit(TransactionImpl.java(Compiled Code))
-
at com.ibm.ws.Transaction.JTA.TransactionImpl.commit(TransactionImpl.java(Compiled Code))
-
at com.ibm.ws.Transaction.JTA.TranManagerImpl.commit(TranManagerImpl.java(Compiled Code))
-
at com.ibm.ws.Transaction.JTA.TranManagerSet.commit(TranManagerSet.java(Compiled Code))
-
at com.ibm.ws.Transaction.JTA.UserTransactionImpl.commit(UserTransactionImpl.java(Compiled Code))
-
at com.ibm.ejs.container.UserTransactionWrapper.commit(UserTransactionWrapper.java(Compiled Code))
-
at .util.transaction.ResourcesJTA.M-T00000(ResourcesJTA.java(Compiled Code))
-
at .util.transaction.TransactionInfo.commit(TransactionInfo.java(Compiled C
-
at .interfaces.Search_TH.invokeStub
-
nested exception is:
-
javax.transaction.RollbackException
-
at com.ibm.ws.Transaction.JTA.TransactionImpl.stage3CommitProcessing(TransactionImpl.java(Compiled Code))
-
at com.ibm.ws.Transaction.JTA.TransactionImpl.processCommit(TransactionImpl.java(Compiled Code))
-
at com.ibm.ws.Transaction.JTA.TransactionImpl.commit(TransactionImpl.java(Compiled Code))
-
at com.ibm.ws.Transaction.JTA.TranManagerImpl.commit(TranManagerImpl.java(Compiled Code))
-
at com.ibm.ws.Transaction.JTA.TranManagerSet.commit(TranManagerSet.java(Compiled Code))
-
at com.ibm.ws.Transaction.JTA.UserTransactionImpl.commit(UserTransactionImpl.java(Compiled Code))
-
at com.ibm.ejs.container.UserTransactionWrapper.commit(UserTransactionWrapper.java(Compiled Code))
-
at .util.transaction.ResourcesJTA.M-T00000(ResourcesJTA.java(Compiled Code))
-
at .util.transaction.TransactionInfo.commit(TransactionInfo.java(Compiled C
-
at .interfaces.Search_TH.invokeStub
-
-
[ERROR] [02 Sep 2009 11:33:18] [Trace.Tools] [WebContainer : 61] - infrastructure:RUN_ID_RECORD_NOT_FOUND: Record not found.
-
[ERROR] [02 Sep 2009 11:33:18] [Trace.Tools] [WebContainer : 61] - infrastructure:RUN_ID_RECORD_NOT_FOUND: Record not found.
-
-
I want to extract the line that contains the "_TH" string only from the 1st instance after finding the 1st "RollbackException" string.
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,501 network members.
|