使用awk对某一列进行求和计算
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用awk对某一列进行求和计算相关的知识,希望对你有一定的参考价值。
使用awk对某一列进行求和计算
cat file.log
file_numb: 3168; total_size: 105.801 GB;avg_size: 34.1983 MB
file_numb: 3154; total_size: 87.16 GB;avg_size: 28.298 MB
file_numb: 348; total_size: 140.047 GB;avg_size: 412.091 MB
file_numb: 306; total_size: 184.478 GB;avg_size: 617.339 MB
file_numb: 3168; total_size: 371.135 GB;avg_size: 119.963 MB
file_numb: 2427; total_size: 0.00790029 GB;avg_size: 0.00333329 MB
file_numb: 3146; total_size: 138.763 GB;avg_size: 45.1663 MB
file_numb: 3168; total_size: 105.801 GB;avg_size: 34.1983 MB
file_numb: 3154; total_size: 87.16 GB;avg_size: 28.298 MB
file_numb: 348; total_size: 140.047 GB;avg_size: 412.091 MB
file_numb: 306; total_size: 184.478 GB;avg_size: 617.339 MB
file_numb: 3168; total_size: 371.135 GB;avg_size: 119.963 MB
file_numb: 2427; total_size: 0.00790029 GB;avg_size: 0.00333329 MB
file_numb: 3146; total_size: 138.763 GB;avg_size: 45.1663 MB
file_numb: 3168; total_size: 105.801 GB;avg_size: 34.1983 MB
file_numb: 3154; total_size: 87.16 GB;avg_size: 28.298 MB
file_numb: 348; total_size: 140.047 GB;avg_size: 412.091 MB
file_numb: 306; total_size: 184.478 GB;avg_size: 617.339 MB
file_numb: 3168; total_size: 371.135 GB;avg_size: 119.963 MB
file_numb: 2427; total_size: 0.00790029 GB;avg_size: 0.00333329 MB
file_numb: 3146; total_size: 138.763 GB;avg_size: 45.1663 MB
awk ‘{sum+=$4} END {print "total =",sum}‘ file.log
total = 3082.18
以上是关于使用awk对某一列进行求和计算的主要内容,如果未能解决你的问题,请参考以下文章
oracle中像使用sum函数对某一列数据进行求和,但是同时需要输出其他字段,怎么求到总数