-2

I have total 64 files with each file name as below:

diffusion-isomalto-thermo1.dat_x.xmgr
diffusion-isomalto-thermo2.dat_x.xmgr
diffusion-isomalto-thermo3.dat_x.xmgr
diffusion-isomalto-thermo4.dat_x.xmgr
.
.
diffusion-isomalto-thermo64.dat_x.xmgr

Each file contains two columns of data in the format:

 5.000     1.047
10.000     1.107
15.000     1.211
20.000     1.083
25.000     1.166
30.000     1.368
35.000     1.179
40.000     1.307
45.000     0.985
50.000     0.954

containing 50,000 lines of data.

What I want is the average of all the first row second column from all files (64 files) and next is average for second row second column over all files.

What is a good approach for this?

4

1 回答 1

2

With GNU awk:

awk 'FNR==1{a+=$2;next}{b+=$2;close(FILENAME);nextfile}END{print a,b}' diffusion*

Assuming the globbing of diffusion* picks up only the 64 files you want. If not use something stricter like diffusion-isomalto-thermo*.dat_x.xmgr.

于 2013-04-18T07:57:33.733 回答