file1 = "misc.txt" file2 = "misc1.txt" with open(file1) as f: a = set(line.strip() for line in f) with open(file2) as f: b = set(line.strip() for line in f) print("---- Lines in misc.txt but NOT in misc1.txt ----") for x in sorted(a - b): print(x) print("\n---- Lines in misc1.txt but NOT in misc.txt ----") for x in sorted(b - a): print(x) hwc@arch ~/m