Optimize huge text file search
I would strongly recommend a different algorithm for processing your file. I would do it in a three-stage approach, requiring only two reads of the file:


on the first stage, we scan the file, and do a few things:


For each line, call the stream.tell() on the file stream, and remember the byte position.
identify all Second_Packet blocks, and the FN they relate to.
store the FN and the byte position from the Tell in to a dictionary.
identify all KEY_FRAME blocks, and create an object to represent it, with it's number. Store it in a list

the second stage involves processing the KEY_FRAME records, and identifying where the Second_Packet records are. From the map, order the requests to happen in byte-position order from the stream.
Here we scan the file again, in order of the Second_Packet byte positions and the KEY_FRAME instances they belong to.


seek in the file to the position of the first needed Second_Packet
strip off whatever information you need to complete the record.
update the KEY_FRAME instance of data with the required information



By performing only two scans through the file (the first is a full scan, the second is an in-order-but-random-and-selective scan) you reduce the amount of times you process the data.

In your current system, you are scanning the file many times (once and then an additional one for each KEY_FRAME record and an additional one again for each second...). The loops you have at the end are very costly:


for s in sentences:
    if any(('FrameNumber = '+f) in s for f in framelist):
        print 'first found'
        #do stuff

    if any(('FN = '+f) in s for f in framelist):
        print 'second found'
        #do stuff