python练习:持续更新
-
[root@host-192-168-2-177 ~]# vi cou.py
#!/usr/bin/python
import re
import fileinput
dics={}
for line in fileinput.input('http.log'):
if line.find('2015')>=0:
Lists=line.split()
# print Lists
if Lists[2] not in dics:
dics[Lists[2]]=1
else:
dics[Lists[2]]+=1
for key,value in dics.items():
print key,value
[root@host-192-168-2-177 ~]# python cou.py
test/robot/r4.c 4
test/robot/r5.c 2
test/robot/login_helper.c 9
system 1
test/robot/robot_cfg.h 2
shell版本(一条命令,还是比较方便的,但是当日志量大的时候用python的效率会高些):
[root@host-192-168-2-177 ~]# more http.log |awk -F " " '{print $3}'|sort| sed '/^$/d'|uniq -c
1 system
9 test/robot/login_helper.c
4 test/robot/r4.c
2 test/robot/r5.c
2 test/robot/robot_cfg.h