Basically, from my code below, I read a new line $line, if its a date, grab and put into date variable, otherwise, process (count and total) the data lines until a date line pops up again, then print the total for the day in an out file. I have ripped this code apart several time until my hair is in a pile on the floor.2003Aug01/ EVENT1: [HEARTBEAT] (IP=1260953,ICMP=898,TCP=1236959,UDP=22477,EVENTS= +950,DROP=0,VER=6.0.1) EVENT1: [HEARTBEAT] (IP=1217149,ICMP=874,TCP=1193416,UDP=22133,EVENTS= +811,DROP=0,VER=6.0.1) 2003Aug02/ EVENT1: [HEARTBEAT] (IP=640626,ICMP=855,TCP=620893,UDP=18614,EVENTS=71 +4,DROP=0,VER=6.0.1) EVENT1: [HEARTBEAT] (IP=652513,ICMP=830,TCP=631758,UDP=19671,EVENTS=72 +2,DROP=0,VER=6.0.1)
With this and other modifications I can get parts to work, but not the whole thing (notice the while/until parts commented above). Any help is GREATLY appreciated !!!#!/usr/bin/perl -w -d use strict; my $date; my $line; my ($tot_ip_cnt,$tot_icmp_cnt,$tot_tcp_cnt,$tot_udp_cnt,$tot_events,$t +ot_drops) = '0'; open (INFILE, "< hbeat-app.log.samp") or die ("Error Opening File $!\n +"); open (OUTFILE, ">> HB_APP_totals.log.CSV") or die ("Error Opening File + $!\n"); print OUTFILE "date,ip_cnt,icmp_cnt,tcp_cnt,udp_cnt,events,drops \n"; while ( my $line = <INFILE>) { if ($line =~ m/^(\d{4})(\w{3})(\d+).+/) { $date = join ' ',($2,$3,$1); next; } else { # while ($line =~ m/^EVENT1\:\s+\[\w+\]\s+\(IP\=(\d+)\,ICMP\=(\d+) +\,TCP\=(\d+)\,UDP\=(\d+)\,EVENTS\=(\d+)\,DROP\=(\d+)\,.+/) { until ($line =~ m/^(\d{4})(\w{3})(\d+).+/) { $tot_ip_cnt += $1; $tot_icmp_cnt += $2; $tot_tcp_cnt += $3; $tot_udp_cnt += $4; $tot_events += $5; $tot_drops += $6; print "$line \n"; next; print "$line \n"; } } print OUTFILE "$date,$tot_ip_cnt,$tot_icmp_cnt,$tot_tcp_cnt,$tot_ud +p_cnt,$tot_events,$tot_drops\n"; } close OUTFILE; close INFILE;
In reply to Looping Headaches by ACiD
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |