以下是实现代码,不过,大家可以使用shell去实现很简单
[root@localhost conf]# cat r.py
import sys
import re
file=open('httpd.conf')
try:
all_file=file.read()
pattern = re.compile('(^[^#|\n]+)', re.M)
result = pattern.findall(all_file)
for x in result:
print x
finally:
file.close()
转载于:https://blog.51cto.com/youzao/1301890