You can try with python. I use the combinations()
function from the itertools
module and join()
the contents of each pair of files. Note that I use a cache to avoid reading each file many times, but you could exhaust your memory, so use the best approach for you:
import sys
import itertools
seen = {}
for files in itertools.combinations(sys.argv[1:], 2):
outfile = ''.join(files)
oh = open(outfile, 'w')
if files[0] in seen:
f1_data = seen[files[0]]
else:
f1_data = open(files[0], 'r').read()
seen[files[0]] = f1_data
if files[1] in seen:
f2_data = seen[files[1]]
else:
f2_data = open(files[1], 'r').read()
seen[files[1]] = f2_data
print('\n'.join([f1_data, f2_data]), file=oh)
A test:
Assuming following content of three files:
==> file1 <==
file1 one
f1 two
==> file2 <==
file2 one
file2 two
==> file3 <==
file3 one
f3 two
f3 three
Run the script like:
python3 script.py file[123]
And it will create three new files with content:
==> file1file2 <==
file1 one
f1 two
file2 one
file2 two
==> file1file3 <==
file1 one
f1 two
file3 one
f3 two
f3 three
==> file2file3 <==
file2 one
file2 two
file3 one
f3 two
f3 three