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
Icecrack
174 Recognized Expert New Member
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
joeferns79
37 New Member
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 Recognized Expert New Member
are you ever calling your Sub ? ever ?


Add this above sub genreport {
Expand|Select|Wrap|Line Numbers
  1. &genreport;
Apr 22 '09 #23
joeferns79
37 New Member
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 Recognized Expert New Member
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
joeferns79
37 New Member
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
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...
0
9376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9326
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,...
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();...
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
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.