with open(filename) as f:
positions = []
for inputline in f:
position = f.tell()
if not positions or position > positions[-1]:
positions.append(position)
inputline = inputline.strip()
if inputline == 'abc':
# the starting position of line number 3 is the ending position of line number 2
f.seek(positions[1])
else:
print(inputline)
def fn(lines, index=0):
for i, line in enumerate(lines, start=index):
if line.strip() == 'abc':
fn(lines, i)
else:
print(line)
with open(filename) as f:
fn(f.readlines())