#!/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)
时间: 2024-10-12 23:38:25