CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
regular expression,log-analyzer

 



Jonas
Deleted

Apr 12, 2001, 12:34 PM

Post #1 of 2 (137 views)
regular expression,log-analyzer Can't Post

hi
i'd like write a log-analyzer for my win98 modem-log-file. the idea is to read out all important data with one regular expression.

($start_date, $start_time,,$remaining)=($log_line=~/(.+?)\s(.+?)\s-\s.+?in use(.+?)closed/s);

$log_line contains the whole log-file in one string with newlines

'01-13-2001 21:05:54.87 - Sportster 56000 MessagePlus EXT in use.
01-13-2001 21:05:54.89 - Modem inf section: Modem4
01-13-2001 22:22:44.90 - Reads : 6236383 bytes
01-13-2001 22:22:44.90 - Writes: 1423440 bytes
01-13-2001 22:22:44.90 - Sportster 56000 MessagePlus EXT closed.'

how do I have to change the above mentioned regular expression to get the time of the last line (22:22:44.90) in the scalar $remaining?

thanks in advance
Jonas



(This post was edited by jonas on Apr 12, 2001, 11:52 AM)


rGeoffrey
User / Moderator

Apr 12, 2001, 9:50 PM

Post #2 of 2 (125 views)
Re: regular expression,log-analyzer [In reply to] Can't Post

It looks like you just want the time of the start and stop lines and not the extra lines in between.

So consider this...


Code
my $log_line = <<EOF; 
01-13-2001 21:05:54.87 - Sportster 56000 MessagePlus EXT in use.
01-13-2001 21:05:54.89 - Modem inf section: Modem4
01-13-2001 22:22:44.90 - Reads : 6236383 bytes
01-13-2001 22:22:44.90 - Writes: 1423440 bytes
01-13-2001 22:22:44.90 - Sportster 56000 MessagePlus EXT closed.
EOF

my $regex = '(\\d{2}\\-\\d{2}\\-\\d{4})\\s+(\\d{2}\\:\\d{2}\\:\\d{2}\\.\\d{2})\\s+\\-\\s+(.*)';
my @rows;

foreach my $line (split ("\n", $log_line)) {
my @fields = ($line =~ m/$regex/);
push (@rows, \@fields) if (($fields[2] =~ m/in use/) || ($fields[2] =~ m/closed/));
}

foreach (@rows) {
print join ("===", @{$_}), "\n";
}

You will probably make some changes, but this should point you in the right direction. I used the d{2} notation so you can add extra parentheses if needed to get month, day, and year separately.

--
Sun Sep 9, 2001 - 1:46:40 GMT, a very special second in the epoch. How will you celebrate?

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives