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_UNHANDL ED", 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 5950 KevinADC 4,059
Recognized Expert Specialist
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.
Kelicula 176
Recognized Expert New Member
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.transacti on.RollbackExce ption.
[ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 49] - infrastructure: ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
infrastructure: RUN_ID_RUNTIME: A runtime exception occurred: javax.transacti on.RollbackExce ption.
i.e. it returns just the line that the string matches and not the full stack.
I want it to return the following ...
[ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 20] - infrastructure: ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
at sun.reflect.Gen eratedMethodAcc essor186.invoke (Unknown Source)
at sun.reflect.Del egatingMethodAc cessorImpl.invo ke(DelegatingMe thodAccessorImp l.java(Compiled Code))
at java.lang.refle ct.Method.invok e(Method.java(C ompiled Code))
at com.ibm.rmi.uti l.ProxyUtil$2.r un(ProxyUtil.ja va(Compiled Code))
at java.security.A ccessController .doPrivileged1( Native Method)
at java.security.A ccessController .doPrivileged(A ccessController .java(Compiled Code))
at com.ibm.rmi.uti l.ProxyUtil.inv okeWithPrivileg e(ProxyUtil.jav a(Compiled Code))
at com.ibm.CORBA.i iop.ClientDeleg ate.invoke(Clie ntDelegate.java (Compiled Code))
at $Proxy90.invoke (Unknown Source)
nested exception is:
infrastructure: RUN_ID_RUNTIME: A runtime exception occurred: javax.transacti on.RollbackExce ption.
at sun.reflect.Gen eratedMethodAcc essor186.invoke (Unknown Source)
at sun.reflect.Del egatingMethodAc cessorImpl.invo ke(DelegatingMe thodAccessorImp l.java(Compiled Code))
at java.lang.refle ct.Method.invok e(Method.java(C ompiled Code))
at com.ibm.rmi.uti l.ProxyUtil$2.r un(ProxyUtil.ja va(Compiled Code))
at java.security.A ccessController .doPrivileged1( Native Method)
at java.security.A ccessController .doPrivileged(A ccessController .java(Compiled Code))
at com.ibm.rmi.uti l.ProxyUtil.inv okeWithPrivileg e(ProxyUtil.jav a(Compiled Code))
at com.ibm.CORBA.i iop.ClientDeleg ate.invoke(Clie ntDelegate.java (Compiled Code))
at $Proxy90.invoke (Unknown Source)
[ERROR] [06 Apr 2009 09:46:02] [Trace] [WebContainer : 49] - infrastructure: ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
at sun.reflect.Gen eratedMethodAcc essor186.invoke (Unknown Source)
at sun.reflect.Del egatingMethodAc cessorImpl.invo ke(DelegatingMe thodAccessorImp l.java(Compiled Code))
at java.lang.refle ct.Method.invok e(Method.java(C ompiled Code))
at com.ibm.rmi.uti l.ProxyUtil$2.r un(ProxyUtil.ja va(Compiled Code))
at java.security.A ccessController .doPrivileged1( Native Method
Kelicula 176
Recognized Expert New Member
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?
Kelicula 176
Recognized Expert New Member
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...sorr y.
KevinADC 4,059
Recognized Expert Specialist
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.
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"
>>>c = extract(a,b)
>>>print c
"abcdefghijklmnop"
|
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.
|
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'\\*\\').
|
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..
|
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 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:
|
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...
|
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: 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...
|
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,...
| |
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |