计算用awk从多个文件平均 [英] calculating average using awk from multiple files

查看:121
本文介绍了计算用awk从多个文件平均的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有500个文件,名称fort.1,fort.2 ... fort.500。每个文件都包含如下800个数据:

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结果
     4 0.979结果
     5 0.338结果
     6 0.891结果
     7 0.415结果
     8 0.368结果
     9 0.245结果
    10 0.489

1 0.485
2 0.028
3 0.100
4 0.979
5 0.338
6 0.891
7 0.415
8 0.368
9 0.245
10 0.489

欲从每个文件获得第二列的每行的平均值。换句话说,获得在output.file的所有文件和存储第二列的第一行的平均。然后获得相同的output.file二线和存储的第二列的平均值。
我试着用粘贴命令,但未能得到我想要的东西。
有没有什么办法在AWK办?

I want to get the average of each line of second column from every file. In other words, get average of second column first line from all files and store in "output.file". Then get average of second column of second line and store in the same "output.file". I tried with paste command but fail to get what I want. IS there any way to do in AWK?

鸭preciate任何帮助。
谢谢

Appreciate any help. Thanks

推荐答案

AWK不会对第一列的假设:

awk without any assumption on the 1st column:

awk '{a[FNR]+=$2;b[FNR]++;}END{for(i=1;i<=FNR;i++)print i,a[i]/b[i];}' fort.*

这篇关于计算用awk从多个文件平均的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆