我有一个python脚本,它使用regex从日志文件中检索数据,而运行脚本时,我得到一个错误sre_constants.error: unbalanced parenthesis。在
下面是我尝试使用regex的脚本。在#!/grid/common/pkgs/python/v2.7.10/bin/python
import sys
import re
var1 = ''
var2 = ''
Html_file= open("/home/karn/healthCheck_result.html","w")
html_str = """
Hostname | Service |
---|
"""
Html_file.write(html_str)
fh=open(sys.argv[1],"r")
for line in fh:
pat_match=re.match("^\s+\HostName:\s+(.*?)\.*", line)
pat_match1=re.match("^\s+(.*?\)Service Status:\s+(.*Not.*?)\.*", line)
if pat_match:
Html_file.write("""
""" + pat_match.group(1) + """\n""")elif pat_match1:
Html_file.write("""
""" + pat_match1.group(2) + """\n""")My log file has the below sample data: Where i'm searching the "Not" String and if it gets that then print that entire line Starting with Service Status.^{pr2}$
你能告诉我这里有什么问题吗。。在