Home > Enterprise >  Compare all files of a folder pairwise
Compare all files of a folder pairwise

Time:12-26

Input:

z2042
z0138
z0189
z2294

Hello,

I want to compare all files in a folder with each other to see, if they are different. So like: z2042 with z0138, z0138 with z0189, z0189 with z2042 and so on...

I know how to compare all files with a single file:

for i in ./z*; do diff -q "$i" z2294; done

But i dont know how to compare all files with all. I tried it with another for loop for with the Variable "x" instead of z2294, but it didnt work :/

Thx for help

CodePudding user response:

z_files="./z*"
for i in $z_files; do
  for j in $z_files; do
    if [ "$i" != "$j" ]; then
      diff -q "$i" "$j"
    fi
  done
done
  •  Tags:  
  • bash
  • Related