#!/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,$tot_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 = ) { 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_udp_cnt,$tot_events,$tot_drops\n"; } close OUTFILE; close INFILE;