I have four files in my directory: say a.txt; b.txt; c.txt; d.txt. I would like to join every file with all other files based on two common columns (i.e. join a.txt with b.txt, c.txt and d.txt; join b.txt with a.txt, c.txt and d.txt; join c.txt with a.txt, b.txt and d.txt). To do this for two of the files I can do:
join -j 2 <(sort -k2 a.txt) <(sort -k2 b.txt) > a_b.txt
How do I write this in a loop for all files in the directory? I've tried the code below but that's not working.
for i j in *; do join -j 2 <(sort -k2 $i) <(sort -k2 $j) > ${i_j}.txt
Any help/direction would be helpful! Thank you.