If I have n files in a directory, for example;
a
b
c
How do I get pairwise combinations of these files (non-directional) to pass to a function?
The expected output is
a-b
a-c
b-c
so that it can be passed to a function like
fn -file1 a -file2 b
fn -file1 a -file2 c
...
This is what I am trying out now.
for i in *.txt
do
for j in *.txt
do
if [ "$i" != "$j" ]
then
echo "Pairs $i and $j"
fi
done
done
Output
Pairs a.txt and b.txt
Pairs a.txt and c.txt
Pairs b.txt and a.txt
Pairs b.txt and c.txt
Pairs c.txt and a.txt
Pairs c.txt and b.txt
I still have duplicates (a-b is same as b-a) and I am thinking perhaps there is a better way to do this.