I am using Python to read a file of the following format:

iter1  

iter2  

iter3  

[n lines of stuff]  

FLAG = value 

iter1  

iter2  

iter3  

iter4  

iter5  

[n lines of stuff]  

FLAG = value  

etc.... 

I want to to search for FLAG, read that value, and then rewind back by 'n' lines and read the value of the final iteration. Note that there are not always the same number of iterations. The number of lines 'n' is consistent within each file; however, these lines may contain different numbers of bytes so I am having trouble using the seek feature.

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() #mark original spot  
          f.seek(-n,1)  #rewind by n lines  
          b = re.search('iter')  
          print b  
          f.seek(spot) #return to FLAG line, continue to next data set  

```