Hi - a couple people responded to this with incomplete answers such as:
#!/usr/bin/perl
use strict;
use warnings;
$_ = do { local $/; <> };
my %tags = /(\w+\s?\w+):\s+(\S+)/g;
for (keys %tags) {
print "$_ : $tags{$_}\n";
}
And here's the output from your sample file:
WARNINGS : 000000001
MANIFEST : 079608023
TIME : 10:16:29
RECEIPT DATE : 04/06/2002
MAILER : 077974868
GOOD RECORDS : 000000035
REPORT : CBD514C0
DATE : 04/06/2002
RECORDS READ : 000000035
MAILING DATE : 04/06/2002
EDIT ERRORS : 000000000
RECEIPT TIME : 10.16.29
PAGE : 1
ENTRY FACILITY : 06101
--> this is great but does not address the following fields in the error file which instead of a tag value format use a header/column format.
ERR/ MANIFEST WRN LINE NO. PIC ERROR FIELD ERROR MESSAGE
W 000000025 9102077974868200018250 07783 INVALID DESTINATION ZIP CODE
The other outstanding issue is the error file could have have multiple reports - so i need to loop over it, but this is secondary.
LOOK !!! - A WORKING ANSWER IS WORTH 1000 POINTS TO ME - I NEED BY 5:00 EST PLEASE!
THANKS,
JEFF
I need a solution - preferably a regex - that will parse the following tag value pairs of this error report:
USPS PRODUCT TRACKING SYSTEM PAGE: 1
REPORT: CBD514C0 MANIFEST DATA EDIT ERROR/WARNING LISTING DATE: 04/06/2002
TIME: 10:16:29
MAILER: 077974868 ENTRY FACILITY: 06101
MANIFEST: 079608023 MAILING DATE: 04/06/2002
RECEIPT DATE: 04/06/2002
RECEIPT TIME: 10.16.29
ERR/ MANIFEST
WRN LINE NO. PIC ERROR FIELD ERROR MESSAGE
W 000000025 9102077974868200018250 07783 INVALID DESTINATION ZIP CODE
RECORDS READ: 000000035
EDIT ERRORS: 000000000
WARNINGS: 000000001
GOOD RECORDS: 000000035
As you'll see, I have a small program that reads in each line & a faulty regex that just grabs the "tags" not the values. to run - save the above to d:\\bill\\newTracking\\Usp
s\\errwrno
1.rpt.0406
0822 save to any file & adjust the "open" line below accordingly.
i'm open to any working solution - speed would be good as it needs to read a million records - i'm guessing just an update to the regex as i'm clueless.
thanks so much
jeff
#!/usr/bin/perl
use DBI;
&doConn;
&doMain;
##########################
##########
##########
########
#
# Grab the file to parse, loop over line by line
#
##########################
##########
##########
########
sub doMain{
#open (LOGFILE, "$filename") or die "can't open $filename: $!";
open (LOGFILE, "d:\\bill\\newTracking\\Us
ps\\errwrn
o1.rpt.040
60822") or die "can't open $filename: $!";
$naptime=1;
undef($hostname);
while (<LOGFILE>) {
$line = $_;
chomp($line);
if ( $line ne "" ) {
&process_line($line);
print "-----------------n e x t-------------------\n";
}
}
close ( LOGFILE );
}
##########################
##########
##########
########
#
# Parse each line down to the desired element
#
##########################
##########
##########
########
sub process_line() {
#while($line)
{
if($line=~/^(.+?)\s+\d/)
{
push(@$names, $1);
}
print "current value: @$names\n";
}
}