I have ~200 short text files (50kb) that all have a similar format. I want to find a line in each of those files that contains a certain string and then write that line plus
I think your problem is the tabs of the bottom file.
You need to indent from if Lines[i] until after i=i+1 such as:
Lines[i]
i=i+1
while i < 500: if Lines[i] == searchquery: f2.write(Lines[i]) f2.write(Lines[i+1]) f2.write(Lines[i+2]) i = i+1 else: i = i+1