roadtest has asked for the wisdom of the Perl Monks concerning the following question:
use warnings; use strict; use Time::Local; my ($ReadOp, $WriteOp); while (<DATA>) { next if ($. == 1); chomp; my @output = split/,\s?/; if ( $output[2] eq "W" ) { $WriteOp -> {$output[1]}{$output[4]} += $output[3]; } elsif ( $output[2] eq "R") { $ReadOp -> {$output[1]}{$output[4]} += $output[3]; } } print "=======\n"; print "WriteOperation\n"; print "=======\n"; for my $ip(keys %{$WriteOp}) { my $files= ${$WriteOp}{$ip}; for my $file(keys %{$files}) { print "$ip => $file => ${$WriteOp}{$ip}{$file}\n"; } } print "\n\n\n"; print "=======\n"; print "ReadOperation \n"; print "=======\n"; for my $ip(keys %{$ReadOp}) { my $files= ${$ReadOp}{$ip}; for my $file(keys %{$files}) { print "$ip => $file => ${$ReadOp}{$ip}{$file}\n"; } } __DATA__ Sun Aug 21 12:08:21 2011,172.22.32.28, W, 4964,/export/file1.log Sun Aug 21 12:08:21 2011,172.22.32.28, W, 4964,/export/file2.log Sun Aug 21 12:08:21 2011,172.22.32.28, W, 4963,/export/file2.log Sun Aug 21 12:08:21 2011,172.22.112.141, W, 9292,/export/home/another. +file Sun Aug 21 12:08:21 2011,172.22.32.28, W, 4964,/export/file2.log Sun Aug 21 12:08:21 2011,172.22.32.28, W, 2493,/export/file1.log Sun Aug 21 12:08:21 2011,172.22.32.28, W, 2355,/export/another.log Sun Aug 21 12:08:21 2011,172.22.32.28, R, 25,/export/another.log Sun Aug 21 12:08:21 2011,172.20.220.38, W, 3699,/export/file2.log Sun Aug 21 12:08:21 2011,172.20.220.146, W, 1996,<?> Sun Aug 21 12:08:21 2011,172.22.32.28, W, 2776,/export/file1.log Sun Aug 21 12:08:21 2011,172.22.32.28, R, 26,/export/file1.log
==============================
Hello gurus,
I have some raw data as following. How can I aggregate them to a report format, so that we can see total data transferred from which IP to which file. I consider using reference to parse the original data. What is the data structure I should use? Is there better way to achieve it?
Thanks in advance,
====expected report format=======
IP Write/Read TotalTransferData FileName 172.22.32.28 W 6736 /export/file1.log 172.22.220.38 W 6737 /export/file2.log
===raw data================================
# ##DATE IP Write/Read TransferData FileName # Sun Aug 21 12:08:21 2011,172.22.32.28, W, 4964,/export/file1.log Sun Aug 21 12:08:21 2011,172.22.32.28, W, 4964,/export/file2.log Sun Aug 21 12:08:21 2011,172.22.32.28, W, 4963,/export/file2.log Sun Aug 21 12:08:21 2011,172.22.112.141, W, 9292,1102,/export/home/ano +ther.file Sun Aug 21 12:08:21 2011,172.22.32.28, W, 4964,/export/file2.log Sun Aug 21 12:08:21 2011,172.22.32.28, W, 2493,/export/file1.log Sun Aug 21 12:08:21 2011,172.22.32.28, W, 2355,/export/another.log Sun Aug 21 12:08:21 2011,172.20.220.38, W, 3699,/export/file2.log Sun Aug 21 12:08:21 2011,172.20.220.146, W, 1996,<?> Sun Aug 21 12:08:21 2011,172.22.32.28, W, 2776,/export/file1.log
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: aggregate data
by NetWallah (Canon) on Aug 25, 2011 at 04:50 UTC | |
|
Re: aggregate data
by duyet (Friar) on Aug 25, 2011 at 08:15 UTC | |
|
Re: aggregate data
by CountZero (Bishop) on Aug 25, 2011 at 19:45 UTC | |
by roadtest (Sexton) on Aug 26, 2011 at 14:43 UTC | |
|
Re: aggregate data
by Anonymous Monk on Aug 25, 2011 at 04:06 UTC |