python脚本之过滤关键字
12345678910111213141516171819202122232425262728293031323334353637383940414243444546#!/usr/bin/envpython#coding:utf8...
·
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#!/usr/bin/env python
#coding:utf8
import os
import sys
import fileinput
import glob
path = '.'
egrep_file = sys.argv[1]
def grep(egrep_file):
index = []
if os.path.exists(egrep_file):
with open(egrep_file) as f:
lines = f.readlines()
for i in lines:
s = i.strip()
if len(s) > 0:
index.append(s)
return index
ret = grep(egrep_file)
file = r'zhaopin*'
files = glob.glob(file) #获取所有匹配路径
print (files)
#print (ret)
for i in files:
if os.path.isfile(i): #判断路径是否为文件
with open(i) as f:
lines = f.readlines()
for line in lines:
for grep_s in ret:
if grep_s in line:
print i,
# print line,
# s = line.replace(grep_s,'\033[32;%s\033[0m'%grep_s')
s = line.replace(grep_s,'\033[1;31;40m;%s\033[0m'%grep_s)
print (s)
|
本文转自 Anonymous123 51CTO博客,原文链接:http://blog.51cto.com/woshitieren/1789225
更多推荐



所有评论(0)