Here is an algorithm to do what you want with two unsorted files. This algorithm has the advantage of needing only one of the files in memory and has a time complexity that is linear in the sum of the lengths of the input files. In other words, this algorithm uses small amounts of memory and of time--many other algorithms will take more space or time. (The answer by @dede seems to work well and is simpler than mine but it uses both more memory and more time, which will be very noticeable for large input files.)
First, read through the first file, line by line, and build a dictionary from it. Each key is a tuple of the first two items in a line, and the corresponding value is the rest of the line. In your second example the resulting dictionary would be
{('Brad', 'Pitt'): 'cherries', ('Angelina', 'Jolie'): 'bred', ('Jack', 'Nicholson'): 'apples', ('Nicole', 'Kidman'): 'cucumber'}
You then create an empty output file and read through the second input file line by line. For each line, you see if the first two items are in the dictionary. If so, print your desired line to the output file. If not, do nothing with that line.
Your main use of memory is then the dictionary. You went through each input file only once and line by line, so it is fast. The main possible weakness of this approach is that the output file will be in the order that the items were in the second input file, which is the order in your second example. If you desire the order of the first input file instead, just swap the usage of the two input files.
Here is my code from that algorithm. This version assumes that each input line has exactly three items separated by spaces or tabs. If the "third item" in a line could include a space or a tab, the code would need to be complicated a little. Using your example input files, the results from this code are just what you wanted.
def similar_columns(filenameinput1, filenameinput2, filename_output):
"""Find the similar columns in two files.
This assumes each line has exactly three items.
"""
# Build a dictionary of the items in the first input file
items_dict = {}
with open(filenameinput1, 'r') as inputfile1:
for line in inputfile1:
col0, col1, oldcolrest = line.split()
items_dict[(col0, col1)] = oldcolrest
# Compare the items in the second input file, saving matches
with open(filenameinput2, 'r') as inputfile2, \
open(filename_output, 'w') as outputfile:
for line in inputfile2:
col0, col1, newcolrest = line.split()
oldcolrest = items_dict.get((col0, col1), None)
if oldcolrest is not None:
outputfile.write('{} {} {} {}\n'.format(
col0, col1, oldcolrest, newcolrest))
similar_columns('f1.txt', 'f2.txt', 'f12.txt')
similar_columns('shop1.txt', 'shop2.txt', 'total.txt')