I have 500 files with name fort.1, fort.2 ... fort.500. Each file contains 800 data as below:
1 0.485
2 0.028
3 0.100
Here's a quick way using paste
and awk
:
paste fort.* | awk '{ for(i=2;i<=NF;i+=2) array[$1]+=$i; if (i = NF) print $1, array[$1]/NF*2 }' > output.file
Like some of the other answers; here's another way but this one uses sort
to get numerically sorted output:
awk '{ sum[$1]+=$2; cnt[$1]++ } END { for (i in sum) print i, sum[i]/cnt[i] | "sort -n" }' fort.*