in reply to aggregate data
output:use Modern::Perl; use Data::Dump qw/dump/; my %database; while (<DATA>) { next if /^#/; chomp; my (undef, $ip, $rw, $amount, $file) = split /,\s?/; $database{$ip}{$rw}{$file} += $amount; } say dump(\%database); __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,/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.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
Caution: this script does not perform any checking whether the data is in a valid format! For instance, your 4th data-line is in a "wrong" format which I assume is just a typo and I "corrected" it by hand.{ "172.20.220.146" => { W => { "<?>" => 1996 } }, "172.20.220.38" => { W => { "/export/file2.log" => 3699 } }, "172.22.112.141" => { W => { "/export/home/another.file" => 9292 } } +, "172.22.32.28" => { W => { "/export/another.log" => 2355, "/export/file1.log" => 10233, "/export/file2.log" => 14891, }, }, }
Printing the results in a pretty format is left as an exercise for the reader.
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: aggregate data
by roadtest (Sexton) on Aug 26, 2011 at 14:43 UTC |