使用awk命令列的求和值 [英] Summing values of a column using awk command

查看:299
本文介绍了使用awk命令列的求和值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要总结列中的所有行的值3.如何做到这一点?

I want to sum the values of all rows in the column 3. How can I do this?

输入:

chr19   10 11
chr19   12 15
chr19   11 29
chr19   a0 20

期望的输出:

75

推荐答案

只是第三列的值存储到一个变量,并添加值与下一行的第三列中的值present,同样为所有。 Atlast,变量计数包含在第三列中的所有的数字present的总和。

Just store the value of third column into a variable and add that value with the value present in the third column of next line, likewise for all. Atlast, the variable count contains the sum of all the numbers present in the third column.

$ awk '{count=count+$NF}END{print count}' file
75
$ awk '{count=count+$3}END{print count}' file
75

这篇关于使用awk命令列的求和值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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