Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Regexp to read through log file and convert into pipe delimited file?.

by CountZero (Bishop)
on Nov 25, 2012 at 10:06 UTC ( #1005473=note: print w/ replies, xml ) Need Help??


in reply to Regexp to read through log file and convert into pipe delimited file?.

Two nested while loops and some regex:

use Modern::Perl; while (<DATA>) { my ($month, $day, $year, $time, $ampm) = (split ' ')[0 .. 4]; next unless $ampm and $ampm =~ m/AM|PM/i; my $datetime = join ' ', ($month, $day, $year, $time, $ampm); my $xml; my $level; my $orderID; my $orderNumber; while (<DATA>) { if (/([^:]+)\s*:\s*((Authenticate RequestXML)|(Authenticate Re +sponseXML)|(Authorize ResponseXML))\s*:\s*<CardinalMPI>/i){ $level = $1; $xml = $2; } if (m|<OrderId>(\d+)</OrderId>|) { $orderID = $1; } if (m|<OrderNumber>(\d+)</OrderNumber>|) { $orderNumber = $1; } if (m|^</CardinalMPI>$|) { say "$datetime - $level - $xml - $orderNumber - $orderID" +if $xml; last; } } } __DATA__ Nov 16, 2012 5:17:53 AM com.sitapp01.commerce.CentinelUtil.AYCentinelU +til getAuthenticateResponse() FINER: ENTRY Nov 16, 2012 5:17:53 AM com.sitapp01.commerce.CentinelUtil.AYCentinelU +til setAuthenticateRequest() : FINER: ENTRY Nov 16, 2012 5:17:53 AM com.sitapp01.commerce.CentinelUtil.AYCentinelU +til setAuthenticateRequest() : INFO: Authenticate RequestXML : <CardinalMPI> <Version>1.7</Version> <SourceVersion>2.8</SourceVersion> <TransactionPwd>fhsdkjvdxfv</TransactionPwd> <MsgType>cmpi_authenticate</MsgType> <ProcessorId>202</ProcessorId> <Source>JTC</Source> <MerchantId>50515</MerchantId> <TransactionType>HC</TransactionType> <OrderId>8585273913266697</OrderId> <PAResPayload>202&#124;50515&#124;0einiSheyXIFqE4KYrlD&#124;HC</PA +ResPayload> </CardinalMPI> Nov 16, 2012 5:17:53 AM com.sitapp01.commerce.CentinelUtil.AYCentinelU +til setAuthenticateRequest() : FINER: ENTRY Nov 16, 2012 5:17:54 AM com.sitapp01.commerce.CentinelUtil.AYCentinelU +til getAuthenticateResponse() ETC ETC ETC ...
Output:
Nov 16, 2012 5:17:53 AM - INFO - Authenticate RequestXML - - 85852739 +13266697 Nov 16, 2012 5:17:53 AM - SEVERE - Authenticate ResponseXML - 5207694 +- 8585273913266697 Nov 16, 2012 5:18:48 AM - INFO - Authorize ResponseXML - 5207694 - 858 +5273913266697
Proper formatting of the output is left as an exercise for the reader.

Note that you will get some "Use of uninitialized value ..." warnings. This is considered a feature not a bug! It points you to some records which possibly have incomplete data.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics


Comment on Re: Regexp to read through log file and convert into pipe delimited file?.
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1005473]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (16)
As of 2014-08-29 16:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (282 votes), past polls