当前位置: 技术问答>linux和unix
请教各位高手一个shell
来源: 互联网 发布时间:2017-04-16
本文导语: 数据 2013-05-08 11:11:44 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http:// 2013-05-08 11:11:44 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http:// 2013-05-08 11:11:44 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] acce...
数据
2013-05-08 11:11:44 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
2013-05-08 11:11:44 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
2013-05-08 11:11:44 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
2013-05-08 11:11:44 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
2013-05-08 11:11:44 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
2013-05-08 11:11:44 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
2013-05-08 11:11:44 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
2013-05-08 11:11:44 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
2013-05-08 11:11:44 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
2013-05-08 11:11:45 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
2013-05-08 11:11:45 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
2013-05-08 11:11:45 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
2013-05-08 11:11:45 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
我需要的结果是这样的
2013-05-08 11:11:44 9
2013-05-08 11:11:45 4
也就是按时间分组,输出个数
2013-05-08 11:11:44 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
2013-05-08 11:11:44 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
2013-05-08 11:11:44 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
2013-05-08 11:11:44 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
2013-05-08 11:11:44 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
2013-05-08 11:11:44 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
2013-05-08 11:11:44 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
2013-05-08 11:11:44 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
2013-05-08 11:11:44 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
2013-05-08 11:11:45 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
2013-05-08 11:11:45 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
2013-05-08 11:11:45 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
2013-05-08 11:11:45 [com.interceptor.DynamicDataSourceInterceptor]-[ERROR] accessurl: http://
我需要的结果是这样的
2013-05-08 11:11:44 9
2013-05-08 11:11:45 4
也就是按时间分组,输出个数
|
没问题啊,你的问题也可以这样解决
awk -F"[" '{a[$1]+=1}END{for(i in a) print i,a[i]}'
|
给你另一个方法,丰富一下:cut -d ' ' -f 1-2 data.txt | uniq -c | awk '{print $2" "$3" "$1}'
|
在awk之前先sort一把就可以了吧
|
排序
awk -F'[' '{a[$1]++}END{for(i in a) print i,a[i]}' urfile | sort -k1,2
awk -F'[' '{a[$1]++}END{for(i in a) print i,a[i]}' urfile | sort -rk1,2
|
$ awk '{a[$1" "$2]++}END{for(i in a)print i,a[i]}' 1.txt