I just started learning python and regular expressions.
How can I get an output of lines from a log file, where multiple keywords match in the single line?
eg: Get lines which start with "5" and have a timestamp "2014/05/12 02:30:00"? here I have to append these 2 pieces of information and get the count of lines which satisfy it from reading the whole log file.
Keywords are separated by commas in log file - this is one line from the file:
5,14/05/0202:30:00,1,1,94776082043,94776082043,0,1,77100,0,1,77100,,14/05/02 02:30:00,9477000003,,,,,19,14/05/05 02:30:00,0,0,9477000007,9477000003,false,,,,,,,,true,,,0,,5011405020230005752,
Here is the code I have already, which I want to improve:
#!/usr/bin/env python
import re
path = raw_input("Enter path to log file \n")
#/home/harzyne/pythonscripts/smsc_log.old
log = open(path)
count = 0
start = raw_input("Enter Start_Time in format(hh:mm:ss) ")
print(start)
end = raw_input("Enter End_Time in format(hh:mm:ss)")
print(end)
for line in log:
if re.search('^5', line) :
count +=1
print count