仅平均多个文件中的第二列数据

2024-05-14 19:38:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我总共有64个文件,每个文件名如下:

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

每个文件包含以下格式的两列数据:

 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

包含50000行数据。你知道吗

我想要的是所有文件(64个文件)中所有第一行第二列的平均值,接下来是所有文件中第二行第二列的平均值。你知道吗

有什么好办法?你知道吗


Tags: 文件数据文件名格式dat平均值diffusion办法
1条回答
网友
1楼 · 发布于 2024-05-14 19:38:26

使用GNU awk

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

假设diffusion*的globbing只拾取您想要的64个文件。如果不使用更严格的方法,比如diffusion-isomalto-thermo*.dat_x.xmgr。你知道吗

相关问题 更多 >

    热门问题