in reply to group by and sum for two columns
G'day gowthamvels,
What you're after is a very simple exercise in using Text::CSV. Here's the guts of it:
#!/usr/bin/env perl use strict; use warnings; use Data::Dump; use Text::CSV; my $csv = Text::CSV::->new; my %result; while (my $row = $csv->getline(\*DATA)) { $result{$row->[1]}[0] += $row->[6]; $result{$row->[1]}[1] += $row->[7]; } dd \%result; __DATA__ 1234,GP,20170715,0,V,97517,24,0.6 5678,Pack,20170715,0,V,97516,88,1.8 1234,GP,20170715,0,V,97517,22,0.6 5678,Pack,20170715,0,V,97517,183,3.9 1234,PRS,20170715,0,S,97517,261,5.4 5678,PRS,20170715,0,M,97517,36,0.9
Output:
{ GP => [46, 1.2], Pack => [271, 5.7], PRS => [297, 6.3] }
Please post data between <code>...</code> tags (as already requested in responses to this and your last post). Show the data as it appears in the file: do not make records into dot points or otherwise change their original format. Also check what you post, multiple times if necessary, using the "preview" button: in this instance, you posted "col1,...,col7" but there are eight columns, not seven.
— Ken
|
|---|