1. 程式人生 > >使用awk對某一列進行求和計算

使用awk對某一列進行求和計算

print size log 17. total pri sum int avg

使用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對某一列進行求和計算