Isso é relativamente fácil com perl
:
perl -F'\s+' -lane '
push @row, [@F];
END{
@sum = @{pop @row};
@col = (0, (sort {$sum[$b] <=> $sum[$a]} (1..$#sum-1)), $#sum);
for $i ($row[0], (sort {$b->[$#sum] <=> $a->[$#sum]} @row[1..$#row]), \@sum) {
print join "\t", @{$i}[@col]
}
}'