Dear brethren,
I am fairly new to perl and am having difficulty parsing a logfile that does NOT have a common delimiter. A sample from the logfile looks like this:
10/1/2003 2:06:32 AM|1|Checkout Started for US-02-14@comany.com (requested by aad6870)
10/2/2003 2:07:17 AM|1|Checkout Processed for US-02-14@company.com (requested by aad6870)
10/3/2003 2:09:37 AM|1|Checkin Processed for DN-US-02-14@company.com (requested by aad6870)
10/4/2003 9:37:53 AM|1|Checkout Started for DN-US-02-14@company.com (requested by heavis6608)
10/5/2003 9:38:29 PM|1|Checkout Processed for US-02-14@company.com (requested by heavis6608)
10/6/2003 10:10:21 AM|1|Checkout Started for US-02-17@company.com (requested by vm_karthik3521)
I need to parse out the date stamp, the activity 'Checkout Started', the machine 'US-02-14@company.com', and the username 'aad6870'.
What I've started on is the following:
while (<LOGFILE1>)
{
# parse the date field with the '|' delimiter
@dateField = split(/\|/);
# parse the activity field by matching '|1|'word space word
@activityField = split(/\|1\|\w\s\w/);
# Start populating the fields as appropriate
$date = $dateField[0];
$activity = $activityField[0];
## Write the cleaned up data to the data file
print DATAFILE "$date , ";
print DATAFILE "$activity ,";
print DATAFILE "\n";
}
My problem is that the parsing of the activity field returns me the entire row. Can anyone tell me what is wrong with my regular expression for the activifity field?
Am I heading in the right direction or have the I been possessed by Perl gremlins...
Any help or suggestions greatly appreciated....
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.