There are more efficient ways, but here is a solution. I was unsure how you would want the files merged. So, in this solution distinct lines from file1 are written to the new file, then distinct lines from file2 are written to the new file.
# remove_dupes.py
from sys import argv
infile1 = open( str(argv[1]), "r" )
infile2 = open( str(argv[2]), "r" )
try:
outfile = open( str(argv[3]), "w" )
except (IndexError):
outfile = open( 'out', "w" )
if1_arr = infile1.readlines()
if2_arr = infile2.readlines()
tmp_arr = if2_arr
exclude = []
for line in if1_arr:
if line in if2_arr:
exclude.append(line)
else:
outfile.write(line)
for line in if2_arr:
if line not in exclude:
outfile.write(line)
infile1.close()
infile2.close()
outfile.close()
To run:
python3 remove_dupes.py <file1> <file2> <output_file>
If you'd like to turn this into a quicker command-line tool, move the script to a long-term place and add the following line to your .bashrc, .bash_aliases, .zshrc, or equivalent file.
alias mydiff='python3 <path_to_script> '
You can replace 'mydiff' with whatever you'd like to call it. After that you can run the script with:
mydiff <file1> <file2> <output_file>