随便写的,不是很规范,不过满足的你需求了。
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# Run at linux!
import re
file_object = open('/tmp/shell/route.txt')
#route.txt就是你要匹配的文本
output = open('/tmp/shell/route.txt.new', 'w')
for line in file_object:
ifalarm = re.search('上海',line)
if not ifalarm:
output.write(line)
file_object.close()
output.close()