shell或php对某一log日志按时间段进行汇总


有这么一个日志log文件:

   
  7139641 20006   327 327101  6   301 0   1   0   2012-09-10 00:00:00
  
7081849 5902 327 327101 25 251 2 1 0 2012-09-10 00:00:01
7081849 5902 327 327101 50 46 0 5 0 2012-09-10 00:00:01
7139641 20006 327 327101 6 301 0 1 0 2012-09-10 00:00:02
7081849 5902 327 327101 6 323 0 1 0 2012-09-10 00:00:03
7141697 20688 327 327101 1 302 0 1 0 2012-09-10 00:00:03
7139641 20006 327 327101 4 323 0 1 0 2012-09-10 00:00:05
7139641 20006 327 327101 3 323 0 1 0 2012-09-10 00:00:05
7139641 20006 327 327101 9 323 0 1 0 2012-09-10 00:00:05
7139641 20006 327 327101 16 323 0 1 0 2012-09-10 00:00:10

想按最后时间以10分钟为一个时间段进行汇总,期望结果如下:

   
  2012-09-10 0(小时)  1-10(分钟)    180(个订单)
  
2012-09-10 0(小时) 11-20(分钟) 200(个订单)
......
2012-09-10 23(小时) 1-10(分钟) 80(个订单)

用php或shell如何实现上面的统计汇总?

php shell

别╰╮发骚 12 years, 5 months ago
   
  awk '{split($11,tmp,":" );k=$10" "int(tmp[1])"(小时)";M=int(tmp[2]/10);M=M*10"-"(M+1)*10;k=k" "M"(分钟)"; a[k]++}END{for(i in a)print i,a[i]}' 1.txt
 

musicat answered 12 years, 5 months ago

Your Answer