Reputation: 201
I'm trying to compare Dir1 and Dir2 file names without extension. Dir2 is a subfolder of Dir1 so I'm launching the script from Dir1.
Dir1/proof1.txt
Dir1/proof2.txt
Dir1/proof3.txt
Dir1/proof4.txt
Dir1/proof5.txt
Dir1/proof6.txt
Dir1/Dir2/proof1.png
Dir1/Dir2/proof2.png
Dir1/Dir2/proof5.png
And the output I wanted is the file names that exists at Dir1 but not at Dir2:
proof3
proof4
proof6
This is what I'm using (not working) to find Files that are at Dir1 but not at Dir2:
(find . -printf '%P\n' | grep -v Dir2 && find Dir2/ -printf '%P\n' && find Dir2/ -printf '%P\n') | sort | uniq -u
Upvotes: 0
Views: 45
Reputation: 36269
Only testet with clean filenames without whitespace:
for f in proof*.txt ; do test -f "Dir2/$(basename "$f" .txt).png" || echo no match "$f"; done
Upvotes: 1
Reputation: 67567
this should do...
$ comm -23 <(ls -1 | cut -d. -f1) <(ls -1 Dir2/ | xargs -n 1 basename | cut -d. -f1)
may not work as intended if your filenames have .
in them other than separating extension.
Upvotes: 0