I need to open a log file, and print out specific lines that are in between two different patterns.
Beginning = pattern1
Ending = pattern2
This is what I have so far:
def SeeIfDateTimeIsFound():
mylist = []
for line in input_data:
if CTFBeginA in line: # Or whatever test is needed
if re.search(stringA, line) and re.search(stringB, line):
mylist.append((line.strip()))
break
for line in input_data: # This keeps reading the file
if CTFEndinA in line.strip():
nextline = (next(input_data, '').strip())
if CTFEndin not in nextline:
break
else:
if re.search(stringA, line) and re.search(stringB, line):
mylist.append((line.strip()))
if re.search(stringA, line) and re.search(stringB, line):
mylist.append((line.strip()))
return mylist
What I'm trying to do is basically the equivalent of this awk code:
awk '/Beginning/,/Ending/' logfile
One of the problems i have with the python code above is, it only grabs the first line it finds that contains Ending pattern. If there are multiple lines containing Ending, i want the python code to grab every one of them and only stop grabbing them when it has grabbed the last one.