Aqui está uma solução Perl. Ele não espera que os anos sejam classificados, mas precisa ler o arquivo inteiro (bem, as somas de cada coluna, pelo menos) na memória. Contanto que seu arquivo não seja muito grande, ele deve fazer o que você deseja:
#!/usr/bin/env perl
## Read the input file, line by line
while (<>){
## Print and skip the 1st line
if($.==1){
print;
next
};
## Split the fileds into the array @F
@F=split(/\s+/);
## $k (%k) is a hash of hashes. The first element of
## $F ($F[0]) is the year, so $k{$year}{tot} will be
## the nuber of lines for each year.
$k{$F[0]}{tot}++;
## Go through each field add its value
## to $k{$year}{field number}
for($i=1;$i<=$#F;$i++){
$k{$F[0]}{$i}+=$F[$i];
}
}
## Now print the data for each year
foreach $y (sort keys(%k)){
## $y is the year
print "$y ";
## $k{$y}{$i} is the sum of the values for this column/year
## and $k{$y}{tot} is the number of lines for this year
for($i=1;$i<=$#F;$i++){
print " " . $k{$y}{$i}/$k{$y}{tot};
}
print "\n";
}
E aqui está o mesmo script que um forro (longo):
$ perl -ane '$.==1 && do {print; next}; $k{$F[0]}{tot}++;
for($i=1;$i<=$#F;$i++){$k{$F[0]}{$i}+=$F[$i];}
END{foreach $y (sort keys(%k)){
print "$y ";
for($i=1;$i<=$#F;$i++){
print " " . $k{$y}{$i}/$k{$y}{tot};
} print "\n";} }' abraham
year 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
1929 4.6525 0 4.7245 2.9415 1.05175 0.21 -0.06275 -0.19975 -0.3185 -0.42875 -0.533 -0.63225 -0.72775 -0.90775 -1.07525 -1.23075 -1.37525 -1.50925 -1.803 -2.043 -2.23225 -2.37475 -2.47525 -2.5375 -2.571 -2.51425 -2.40125 -2.262 -2.11925 -1.9885 -1.8735 -1.776 -1.69225 -1.62925 -1.5785 -1.4845 -1.39525 -1.311 -1.229 -1.151 -1.075 -1.002 -0.859 -0.721 -0.587 -0.456 -0.328 -0.171 -0.017 0.068 0.151 0.308 0.445 0.559
1930 1.25 0.0005 1.2375 0.65475 0.251 0.049 -0.052 -0.184 -0.30075 -0.409 -0.51125 -0.6085 -0.702 -0.8775 -1.041 -1.193 -1.33475 -1.46675 -1.757 -1.99475 -2.18425 -2.32875 -2.432 -2.499 -2.54225 -2.49625 -2.39325 -2.26075 -2.1225 -1.99275 -1.878 -1.7795 -1.6955 -1.6315 -1.58075 -1.48575 -1.39625 -1.31175 -1.23 -1.15175 -1.076 -1.002 -0.85925 -0.721 -0.587 -0.456 -0.328 -0.171 -0.017 0.068 0.151 0.308 0.445 0.55875
1931 -8.4025 0.057 -5.51075 -1.187 0.0095 0.001 -0.055 -0.1735 -0.2835 -0.38725 -0.4855 -0.57975 -0.67025 -0.84075 -0.9995 -1.148 -1.28625 -1.41575 -1.70075 -1.9365 -2.1255 -2.2715 -2.379 -2.45125 -2.50775 -2.47425 -2.38225 -2.25825 -2.125 -1.99725 -1.883 -1.7835 -1.69825 -1.63325 -1.58275 -1.487 -1.3975 -1.31225 -1.231 -1.152 -1.076 -1.003 -0.86 -0.722 -0.58725 -0.456 -0.328 -0.171 -0.017 0.068 0.151 0.307 0.444 0.558