Hi All,
Thanks for your help before I start.
I need to use Perl again, having used it very elegently and successfully ages ago to interrogate a log file. In this case the log file is <INFILE>. I want to match each line in this file with each reqid in <REQIDS_FILE>. I iterate over the <REQIDS_FILE> and for each reqid I then iterate over <INFILE>, outputting any line matching the reqid. When a matched line also contains an SQL SELECT statement, I also need to output the next 3 lines in <INFILE>. The issue is checking for the existence of reqid in the line from <INFILE>. As you can see from the code, I've tried some stuff but I never get to the MATCHED statement.
The logic is not correct nor is the code complete. The reason for this is that I suspect what I'm trying to do is second nature to many of you. I can post compiled code if you need it.
Any help is much appreciated. Thanks again.
<INFILE>
15:53:42.332 Dbg 10741 'App: 12' has put request id='834531' into queu
+e
15:53:42.332 Dbg 10737 Forwarding request '834531' from 'App: 12' to '
+./dbclient_oracle: 12.1'
15:53:43.908 Dbg 10749 Forwarding response '834531.1' from './dbclient
+_oracle: 12.1' to 'App: 12'
15:53:43.908 Dbg 10749 Forwarding response '834531.2' from './dbclient
+_oracle: 12.1' to 'App: 12'
15:53:43.908 Dbg 10739 Oracle: id='12.1' req='834531' SQL: SELECT crf_
+routing.CRF_RT_ACD1_QUEUE,crf_routing.CRF_RT_ACD1_SIZE,crf_ro'
+0551 Executed SQL statement 'SELECT', start retrieve records...
+0826 MSG_RETRIEVED2 status='DBM_SUCCESS'
+0826 MSG_RETRIEVED status='DBM_NOMORE'
<REQIDS_FILE>
834531
834532
834533
foreach $reqidline (<REQIDS_FILE>)
{
print "reqid - $reqidline\n";
$reqidline =~ s/ */|/g;
+ # Replace multiple spaces with pipe characters
@reqidLineElements = split(/\|/,$reqidline);
+ # Split line elements into an array
$count = 0 ;
print "\tactual reqid - $reqidLineElements[0]\n";
foreach $inline (<IN_FILE>)
{
print "\tinline - $inline\n";
$reqidLineElement = $reqidLineElements[0] ;
print "\textracted reqid - $reqidLineElement\n";
# if ($inline=~m/$reqidLineElement/)
if (834531 == $reqidLineElement)
{
# Write the line from the log to output
$count = 0 ;
next ;
print "\tMATCHED - $inline\n";
}
if ( ($inline =~ /$reqidLineElements[0]/ ) and
+( $inline =~ /SELECT/) )
{
# Write current line to output
print "\tSELECT - $inline\n";
# Initiate the reading of the next 3 li
+nes from the log
$counting = "true" ;
$count = 0 ;
next ;
}
if ( $counting eq "true" )
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.