Aqui está uma maneira de fazer o trabalho com um script perl:
#!/usr/bin/perl
use Data::Dump qw(dump);
my %result;
# open iput file
my $in_file = 'file.txt'; # give the fullpath to the file
open my $fh, '<', $in_file or die "unable to open '$in_file': $!";
# read the file line by line
while(my $line = <$fh>) {
# extract name and year from current line
my ($name, $year) = $line =~ /"([^"]+)","(\d+)/;
# Explode the name into letters
my @letters = split //, $name;
# increment result for each letter, for current year
$result{$year}{$_}++ for @letters;
}
dump%result;
Arquivo de entrada de amostra:
"Given name","2000","Gender"
"another name","2001","Gender"
Saída:
(
2000,
{ " " => 1, "a" => 1, "e" => 2, "G" => 1, "i" => 1, "m" => 1, "n" => 2, "v" => 1 },
2001,
{ " " => 1, "a" => 2, "e" => 2, "h" => 1, "m" => 1, "n" => 2, "o" => 1, "r" => 1, "t" => 1 },
)