Speeding up script for processing three huge files
A major problem with your code is that you're doing very long linear searches to find matches-- worse, you're doing those in a nested fashion. 

Instead, you should take advantage of Python dictionaries, which have very fast lookups.  Something like this:



def read_sentences(filename):
    with open(filename) as fp:
        data = {line[:line.index("#")]: line for line in fp}
    return data

eng_lines = read_sentences("eng_lines.txt")
all_lines = read_sentences("all_lines.txt")

with open("all_links.txt") as fp:
    all_links = dict(line.rstrip().split("#") for line in fp)

with open("matches2.txt", "w") as fp_matches:
    for idcode in sorted(eng_lines, key=int):
        print "working on", idcode
        if idcode in all_links:
            fp_matches.write(eng_lines[idcode] + "\n")
            fp_matches.write(all_lines[all_links[idcode]] + "\n")
        else:
            print "warning: could not match eng_line", idcode




builds dictionaries for both eng_lines and all_lines, using the id as the key and the line as the value.  It also builds a dictionary all_links to store the connection between the id values in eng_lines and all_lines.   On some test data I mocked up, it produces a file looking like yours:

1#eng#This is example sentence number 1

995072#cmn#This should really be in Mandarin 995072

2#eng#This is example sentence number 2

1732074#cmn#This should really be in Mandarin 1732074


in about ten to twenty seconds on a dataset of your size.