I am trying to search for a particular string in every line of a log file, and if that matches, i need to be able to get the Host information from that particular error.
Consider the log entries as below :
05-05-2014 00:02:02,771 [HttpProxyServer-thread-1314] ERROR fd - Empty user name specified in NTLM authentication. Prompting for auth again.
Host=tools.google.com, Port=80, Client ip=/10.253.168.128, port=37271, User-Agent: Google Update/1.3.23.9;winhttp;cup-ecdsa
05-05-2014 00:02:02,771 [HttpProxyServer-thread-2156] ERROR fd - Empty user name specified in NTLM authentication. Prompting for auth again.
Host=tools.google.com, Port=80, Client ip=/10.253.168.148, port=37273, User-Agent: Google Update/1.3.23.9;winhttp;cup-ecdsa
05-05-2014 00:02:02,802 [HttpProxyServer-thread-604] ERROR fd - Empty user name specified in NTLM authentication. Prompting for auth again.
Host=tools.google.com, Port=80, Client ip=/10.253.168.92, port=37280, User-Agent: Google Update/1.3.23.9;winhttp;cup
This is my code :
for line in log_file:
if bool(re.search( r'Empty user name specified in NTLM authentication. Prompting for auth again.', line)):
host = re.search(r'Host=(\D+.\D+.\D+,)', line).group(1)
Problem is the Host information is not in the same line as the error. It is in the next line. How do i get the re.search(r'Host=(\D+.\D+.\D+,)', line).group(1) to search in the next line that "line" is currently in?