Решение Python:
with open('file1.txt') as f1:
ids = set(f1.read().splitlines())
with open('file2.txt') as f2, open('file3.txt', 'w') as f3:
lines = f2.read().splitlines()
for line in lines:
id = line.split()[0]
if id in ids:
f3.write(line + '\n')