I use Python to read a file in the following format:
Iter1
iter2
iter3
[n lines of material]
FLAG = value
Iter1
iter2
iter3
iter4
iter5
[n lines of material]
FLAG = value
, etc.
I want to find the FLAG, read this value, and then rewind to the lines 'n' and read the value of the last iteration. Note that the number of iterations is not always the same. The number of lines "n" is consistent in each file; however, these lines may contain a different number of bytes, so I am having problems using the search function.
I would like to do something like this:
f = open(file)
for i in f:
a = re.search('FLAG')
if a:
print a
spot=f.tell()
f.seek(-n,1)
b = re.search('iter')
print b
f.seek(spot)