从许多文件第二列的同一行平均计算 [英] calculating average of same lines of second column from many files

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

问题描述

我需要做的就用awk多个文件中的某些操作的帮助。
我共有的,每个文件包含800行有两​​列(第1列和第2列)数据的500个文件。

I need a help on doing some operation on multiple files using awk. I have total of 500 files which each file contains 800 lines of data with two columns (1st column and 2nd column).

我想的第一行,要添加的每个文件(来自所有500个文件)的第2列和计算一个新的输出文件的平均值和存储(可以说average.out)。

I want the first line, 2nd column of each file (from all 500 files) to be added and calculate the average and store in a new output file (lets say average.out).

然后接着第二行中的所有文件(所有500文件)的第2列和计算average.out平均值和商店。并继续,直到average.out文件包含800行。

Then it goes on to second line, 2nd column of all files (all 500 files) and calculate the average and store in average.out. And it continues until the "average.out" file contain 800 lines.

我很喜欢之前我的数据计算,其他事情来解决这个计算。希望我的一些见解。

I badly need to solve this calculation before going on with other calculations of my data. Hope I get some insight.

先谢谢了。

推荐答案

这将显示所有的行号和他们的平均水平。

This will display all the line numbers and their averages.

awk '{a[FNR]=a[FNR]+$2;b[FNR]++;}END{for(i in a){print i,a[i]/b[i]}}' *your_file*

有关例如:

LINE_NUMBER its_average。

line_number its_average.

testted如下:

testted below:

> cat temp
1 10 
2 28
3 20
4 79
> cat temp2
1 12 
2 30
3 22
4 81
> awk '{a[FNR]=a[FNR]+$2;b[FNR]++;}END{for(i in a){print i,a[i]/b[i]}}' temp temp2
2 29
3 21
4 80
1 11

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

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