有时候看log的时候是不是希望关键字所在的行都保存到一个文件看呢? Notepad++好像没这个插件,顺手就写了个Python的脚本,需要exe的可以留言转个。
1: import os
2: print "***Keywords to Text file: generate lines that contains your keywords**"
3:
4: def parseKeywords(filepath, keyword_list):
5: fileInput = open(filepath, 'r')
6: fileOutput = open('keywords_output.txt', 'w')
7: lines = fileInput.readlines()
8: for line in lines:
9: for keyword in keyword_list:
10: if keyword in line:
11: fileOutput.write(line)
12: break
13:
14: if __name__ == '__main__':
15: while True:
16: filepath = raw_input('Please input the file path:n')
17: while not os.path.exists(filepath):
18: filepath = raw_input('no %s ' % filepath + 'found! please input the file path again!!n')
19: keyword_list = []
20: print 'Please input the keyword list, use [end] to end inputting: n'
21: keyword = ''
22: while keyword != '[end]':
23: print 'another keywords? or [end]'
24: keyword = raw_input()
25: keyword_list.append(keyword)
26: parseKeywords(filepath, keyword_list);
27: print 'Finish!!'
28: os.system('keywords_output.txt')