I'm trying to use comm to get files on a folder A that is not on B and vice-versa:
comm -3 <(find /Users/rob/A -type f -exec basename {} ';' | sort) <(find "/Users/rob/B" -type f -exec basename {} ';' | sort)
I'm using basename {} ';' to exclude the directory path, but this is the output I get:
IMG_5591.JPG
IMG_5591.jpeg
IMG_5592.JPG
IMG_5592.jpeg
IMG_5593.JPG
IMG_5593.jpeg
IMG_5594.JPG
IMG_5594.jpeg
There's a tab in the name of the first directory, therefore all entries are considered different. What am I doing wrong?
The leading tabs are not being generated by the
find|basenamecode; the leading tabs are being generated bycomm...commgenerates 1 to 3 columns of output depending on the input flags; 2nd column of output will have a leading tab while 3rd column of output will have 2 leading tabs.In this case OP's code says to ignore column #3 (
-3, the files in common between the 2 sources), socommgenerates 2 columns of output w/ the 2nd column having a leading tab.One easy fix:
If for some reason your
commdoes not support the--output-delimiterflag:This assumes the file names do not include embedded tabs otherwise replace the
trwith your favorite code to strip leading white space, eg:Demo ...
Removing the leading tabs: