一行命令获取大文件中特定列的平均值
A one line command to get the average of specific column in big file
我需要设置一个单行命令来获取包含多列的文件中一列中大量数字的平均值,我们需要添加文件名参数和所需的列数大文件
Example: # avgerage_column 3 test
average_column should be the script
3 is the number of the column in the big file
test is the big file
Sample:
210 56687 1792 18 55 26 1
188 21949 961 9 57 34 0
201 1257 521 1 46 54 0
260 11455 641 4 47 49 0
244 16466 756 7 38 55 0
54 1570 651 1 14 85 0
161 619 583 0 28 72 0
88 479 600 0 26 74 0
30 394 670 0 37 63 0
6 3713 369 3 79 18 0
24 16109 553 16 60 24 0
7 877 482 0 68 32 0
84 845 525 0 63 36 0
31 844 492 0 79 21 0
谢谢
在 AWK 中:
awk 'BEGIN { total = 0; count = 0 } { total += ; count += 1; } END { avg = total / count; print avg} ' input.txt
- $3 是第三个字段
- input.txt 是你的大文件。
输出:
685.429
我需要设置一个单行命令来获取包含多列的文件中一列中大量数字的平均值,我们需要添加文件名参数和所需的列数大文件
Example: # avgerage_column 3 test
average_column should be the script
3 is the number of the column in the big file
test is the big file
Sample:
210 56687 1792 18 55 26 1
188 21949 961 9 57 34 0
201 1257 521 1 46 54 0
260 11455 641 4 47 49 0
244 16466 756 7 38 55 0
54 1570 651 1 14 85 0
161 619 583 0 28 72 0
88 479 600 0 26 74 0
30 394 670 0 37 63 0
6 3713 369 3 79 18 0
24 16109 553 16 60 24 0
7 877 482 0 68 32 0
84 845 525 0 63 36 0
31 844 492 0 79 21 0
谢谢
在 AWK 中:
awk 'BEGIN { total = 0; count = 0 } { total += ; count += 1; } END { avg = total / count; print avg} ' input.txt
- $3 是第三个字段
- input.txt 是你的大文件。
输出:
685.429