I have the following example text file (it is in the format as indicated below). I want to extract everything between the lines "Generating configuration...." and "`show accounting log all`", this is the beginning and end of what I am interested in.
some lines
some more line
Generating configuration....
interested config
interested config
interested config
`show accounting log all`
some lines
some more line
I wrote the following code, but its does not stop appending the lines to the textfile after it has found `show accounting log all`.
config_found = False
with open(filename, 'rb') as f:
textfile_temp = f.readlines()
for line in textfile_temp:
if re.match("Generating configuration....", line):
config_found = True
if re.match("`show accounting log all`", line):
config_found = False
if config_found:
i = line.rstrip()
textfile.append(i)
what am i doing wrong with my statements?
show accounting log alland in your code it's looking for single quotes, so it will never match. (Why are you using the regex module re, instead of plain string comparison?)