Hi experts a have a very large file and I need to add two columns: the first one numbering the incidence of records and the another with the total count
The input file:
21 2341 A
21 2341 A
21 2341 A
21 2341 C
21 2341 C
21 2341 C
21 2341 C
21 4567 A
21 4567 A
21 4567 C
21 4567 C
23 4567 A
23 4567 A
23 4567 A
23 4567 A
23 4567 C
23 4567 C
23 4567 C
desired output file:
21 2341 A 1 3
21 2341 A 2 3
21 2341 A 3 3
21 2341 C 1 4
21 2341 C 2 4
21 2341 C 3 4
21 2341 C 4 4
21 4567 A 1 2
21 4567 A 2 2
21 4567 C 1 2
21 4567 C 2 2
23 4567 A 1 4
23 4567 A 2 4
23 4567 A 3 4
23 4567 A 4 4
23 4567 C 1 3
23 4567 C 2 3
23 4567 C 3 3
while(<DATA>){
chomp;
$hash{$_}->{CNT}++;
$hash{$_}->{SEQ}=$.;
}
foreach my $key(sort {$hash{$a}<=>$hash{$b}} keys %hash){
print $key," ",$_," ",$hash{$key}->{CNT},"\n" foreach (1..$hash{$key}->{CNT});
}
__DATA__
21 2341 A
21 2341 A
21 2341 A
21 2341 C
21 2341 C
21 2341 C
21 2341 C
21 4567 A
21 4567 A
21 4567 C
21 4567 C
23 4567 A
23 4567 A
23 4567 A
23 4567 A
23 4567 C
23 4567 C
23 4567 C