I have two text files, A.txt and B.txt.
Each line in A.txt is of the following form:
[Num]WordA1 WordA2 WordA3
WordB1 WordB2 [Num] WordB3 WordB4
Apple Banana Orange
Kiwi Grape Lemon
Blue Red  Green Black
Red White  Purple Green
Brown Pink  Blue Black
Apple Green Banana Orange
Kiwi Blue Grape Lemon
Here is how I would do this with regular expression.
First we open each file.
Then we compare the values of each row inside of the
Once we find a match we can print each line.
import re file_a = open("./A.txt", "r") file_b = open("./B.txt", "r") for a_line in file_a: a = re.findall(r"([0-9]+)", a_line) for b_line in file_b: b = re.findall(r"([0-9]+)", b_line) if a == b: print(a_line) print(b_line) file_a.close() file_b.close()
The results with the date you gave as an example look like this:
Apple Banana Orange Blue Red  Green Black