It's hard to tell without seeing the actual input file (formatted, with newlines intact), but it looks like what you're trying to do is take an input file where entries can span multiple lines, and print it out in a format where each entry is on its own line and the values are separated by tabs.
The problem here is that you are going through the input line by line -- you're using readlines(), which returns a list of lines, and then iterating through it line by line with your loop for line in file:. This won't work because you have to read multiple lines at a time in order to get one entry.
I would propose getting rid of the for line in file: loop and just reading in all of the contents of the file at once, then parsing it down from there. Also, remember that whenever you open() a file, you have to close() it after you're done with it. The best way to do this is with a context manager (see the with open(... line below):
import re
with open("r.txt") as f:
# store the contents of the entire file as a string
data = f.read()
# split the string up into a list (tuple) of entries defined by
# some regex pattern that looks for the entry name (i.e. P####)
re_pattern = r"(good luck writing this regex pattern!)+"
entries = re.match(re_pattern, data).groups()
# for each entry, substitute tabs for spaces and print the result
for entry in entries:
print re.sub(r"\s+", "\t", entry.rstrip())
Now the only problem you would need to solve would be writing a regex pattern that can tell one entry from the next, which is actually quite complicate and would involve "negative lookahead." To be honest, I can't figure out how to use negative lookahead properly :) If you're interested, see the python docs on the re module, which include some very helpful information about regular expression syntax.
Given the complex nature of this problem, I would actually recommend using a parsing library (Python has about 3 billion of them) in order to make things easier on yourself.
Hope that helps... this task is trickier than it seems!