1)使用awk对某一列进行求和计算
[root@localhost ~]# 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

[root@localhost ~]# awk '{sum+=$4} END {print "total =",sum}' file.log
total = 3082.18
备注:
, 号作用是输出结构类似于添加了空格

2)awk实现求和、平均、最大值和最小值的计算操作

查看 cat pjc.txt 文本有一列数字
124
224
324
434
34255
62432
7
824
2324
102423
11
12
1323
14
123245
16243
172
182
194
20
21
22242
23
24
25424
26
1.求和
[root@localhost ~]# cat pjc.txt | awk '{sum+=$1} END {print "sum=",sum}'
sum= 392547
2.求平均数
[root@localhost ~]# cat pjc.txt | awk '{sum+=$1} END {print "Average=",sum/NR}'
Average= 15098
3.求最大数
[root@localhost ~]# cat pjc.txt | awk 'BEGIN {max=0} {if ($1+0>max+0) max=$1 fi} END {print "max =",max}'
max = 123245
4.求最小数
[root@localhost ~]# cat pjc.txt | awk 'BEGIN {min=1000000} {if ($1+0