im kinda new to python and Stackoverflow. forgive me If I did not explain my question properly.
First file (test1.txt):
customer ID age country version
- Alex #1233 25 Canada 7
- James #1512 30 USA 2
- Hassan #0051 19 USA 9
Second file (test2.txt):
customer ID age country version
- Alex #1233 25 Canada 3
- James #1512 30 USA 7
- Bob #0061 20 USA 2
- Hassan #0051 19 USA 1
Results for the missing lines should be
Bob #0061 20 USA 2
Here is the code
missing = []
with open('C:\\Users\\yousi\\Desktop\\Work\\Python Project\\test1.txt.txt','r') as a_file:
a_lines = a_file.read().split('\n')
with open('C:\\Users\\yousi\\Desktop\\Work\\Python Project\\test2.txt.txt','r') as b_file:
b_lines = b_file.read().split('\n')
for line_a in a_lines:
for line_b in b_lines:
if line_a in line_b:
break
else:
missing.append(line_a)
print(missing)
a_file.close()
b_file.close()
The problem with this code is that it compares both files based on the entire line. I only want to check the first 3 columns, if they dont match then it prints the entire line.
new example:
First file (test1.txt)
60122 LX HNN -- 4 32.7390 -114.6357 40 Winterlaven - Sheriff Sabstation
60122 LX HNZ -- 4 32.7390 -114.6357 40 Winterlaven - Sheriff Sabstation
60122 LX HNE -- 4 32.7390 -114.6357 40 Winterlaven - Sheriff Sabstation
second file (test2.txt)
60122 LX HNN -- 4 32.739000 -114.635700 40 Winterlaven - Sheriff Sabstation
60122 LX HNZ -- 4 32.739000 -114.635700 40 Winterlaven - Sheriff Sabstation
60122 LX HNE -- 4 32.739000 -114.635700 40 Winterlaven - Sheriff Sabstation