这篇文章主要介绍了Shell根据web日志计算平均连接时间功能,本文给出了原代码和自己修改后的代码,需要的朋友可以参考下
cat access.log|grep "connect cbp" |awk 'BEGIN{sum=0;count=0;}{sum+=$10;count++;}END{printf("sum=%d,count=%d,avg=%f\n",sum,count, sum/count)}'
cat access.log |awk '{sum+=$10;count+=1} END{print "SUM:"sum"\nAVG:"sum/count"\nCOUNT:"count}'
SUM:33403166
AVG:7951.24
COUNT:4201
cat access.log |awk 'BEGIN{sum=0;count=0;}{sum+=$10;count++;}END{printf("sum=%d,count=%d,avg=%f\n",sum,count, sum/count)}'
sum=33403166,count=4201,avg=7951.241609