brassmon_k has asked for the wisdom of the Perl Monks concerning the following question:
Okay "mon402.log" is the file I'm trying to pattern match in. I left the "$" out at the end of the pattern match line as it kept me from returning anything including errors, I'd just get my prompt again. Now if I leave it off I get the following errors#!/usr/bin/perl -w use strict; my %mylist; my $min; my $max; my $range; my $line; # get the range (in this throwtogether it must be entered # with no spaces in the form HHMMSSTT-HHMMSSTT) # Hour, Minute, Second, Tenths of seconds # Get the range $range = <STDIN>; # Break up the range ($min, $max) = split /-/, $range; # Squeeze out leading and trailing spaces $min =~ s/^\s+//; $min =~ s/\s+$//; $max =~ s/^\s+//; $max =~ s/\s+$//; # Get the filenames and break into fields open(CAT, "cat mon402.log |"); (@ARGV = <CAT>) unless @ARGV; for (@ARGV) { if ($_ =~ m/(\d{2}\-\w{3}\-\d{4})\ (\d{2}\:\d{2}\:\d{2}\.\d{2})/) +{ # push the restricted range of filenames onto a hash of arrays + # keyed on the date field if (($2>= $min) && ($2 <= $max)) { push(@{$mylist{$2}}, $_); } } } my @keys = sort (keys %mylist); foreach my $key (@keys) { foreach my $thing (@{%mylist}{$key}){ foreach my $it (@$thing) { print "$min\n"; print "$max\n"; print "$it\n"; print "$key\n"; print "$thing\n"; print "@keys\n"; last; } } }
Now what I need is for the script to be able to match a time range on the second field right after the date. So when I give it a range such as -27-Jun-2001 12:08:19.17 SendSMReq:T:1069 D:19203311338 O:Voice Mail M +WI P:0x20 C:0xe0 V:07-05 12:08 <20> 27-Jun-2001 12:08:19.36 SendSMCnf:AbsSub:1068 27-Jun-2001 12:08:19.56 SubmitInd:T:0 D:19207024720 O:19202928411 P:0 +x0 C:0x0 V:09-11 12:08 <yeah> 27-Jun-2001 12:08:20.05 SubmitInd:T:0 D:19207137406 O:19203314700 P:0 +x0 C:0x0 V:06-28 12:08 <LAST GF WAS 19 WAY TO IMMATURE, SUCKED IN BED +> 27-Jun-2001 12:08:20.30 SendSMReq:T:1070 D:16083089587 O:16083089560 +P:0x20 C:0x0 V:07-05 11:02 <good morning sleepy head> 27-Jun-2001 12:08:20.31 SubmitRsp:0 27-Jun-2001 12:08:20.32 SubmitRsp:0 27-Jun-2001 12:08:21.62 SendSMCnf:StatOK:1065 27-Jun-2001 12:08:22.36 SendSMCnf:StatOK:1060 27-Jun-2001 12:08:22.56 SendSMCnf:StatOK:1063
Edit: chipmunk 2001-07-09
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: pattern match or key problem
by tachyon (Chancellor) on Jul 10, 2001 at 02:23 UTC | |
|
Re: pattern match or key problem
by frag (Hermit) on Jul 10, 2001 at 02:40 UTC | |
|
Re: pattern match or key problem
by John M. Dlugosz (Monsignor) on Jul 10, 2001 at 02:01 UTC | |
|
Re: pattern match or key problem
by brassmon_k (Sexton) on Jul 11, 2001 at 19:12 UTC |