Selecting files with one extensions that have the same name as files with a different extension I have two folders of images. In one folder there are .JPGs, e.g.


  
  001.jpg
  002.jpg
  003.jpg
  004.jpg
  005.jpg
  006.jpg
  007.jpg
  008.jpg
  


in the other folder, there are .NEFs. However some of the .NEFs have been deleted, so there are e.g.


  
  001.nef
  003.nef
  004.nef
  005.nef
  008.nef
  


The jpgs and nefs correspond to one another - they are the same photograph taken at the same time with the same efix data (saved to two seperate memory cards)

What I want to do is select the .JPGs that correspond to the remaining .NEFs. In the above example I want to select JPGs 1,3,4,5,8 but not the others. I actually have around 400 jpgs and 800 nefs.

I have tried using folder comparison apps such as VisualDiffer however they seem to only work if you're using the same full file name + extension.

Does anybody know how it might be possible to achieve this in finder or using terminal? or alternatively with a different app?

I am using Mac OSX 10.6.8

Thanks!
Open terminal and use cd to make the directory of *.nef files your current directory. Let's assume you have this structure:

mydir/jpegdir
mydir/nefdir

So cd into mydir/nefdir

Then:

mkdir newdir
for file in *.nef; do 
    root=${$file%.nef}; 
    jpeg=${root}.jpg; 
    mv ../jpegdir/${jpeg} ./newdir/
done


example below. Note here that I put "echo" in front of the mv command. You want to omit that, but I often use it when I'm checking that a script is doing what I expect before executing it. You also don't say what you want to do with the files, but moving them to a new folder allows you to select them, and you can always move them all back. I also shortened my tmp variable names.

$ ls -R
total 0
drwxrwxr-x  4 tim  staff  136 Jun 13 08:02 .
drwx------  9 tim  staff  306 Jun 13 08:02 ..
drwxrwxr-x  8 tim  staff  272 Jun 13 08:03 jpegdir
drwxrwxr-x  5 tim  staff  170 Jun 13 08:03 nefdir

./jpegdir:
total 0
drwxrwxr-x  8 tim  staff  272 Jun 13 08:03 .
drwxrwxr-x  4 tim  staff  136 Jun 13 08:02 ..
-rw-rw-r--  1 tim  staff    0 Jun 13 08:03 foo1.jpeg
-rw-rw-r--  1 tim  staff    0 Jun 13 08:03 foo2.jpeg
-rw-rw-r--  1 tim  staff    0 Jun 13 08:03 foo3.jpeg
-rw-rw-r--  1 tim  staff    0 Jun 13 08:03 foo4.jpeg
-rw-rw-r--  1 tim  staff    0 Jun 13 08:03 foo5.jpeg
-rw-rw-r--  1 tim  staff    0 Jun 13 08:03 foo6.jpeg

./nefdir:
total 0
drwxrwxr-x  5 tim  staff  170 Jun 13 08:03 .
drwxrwxr-x  4 tim  staff  136 Jun 13 08:02 ..
-rw-rw-r--  1 tim  staff    0 Jun 13 08:03 foo2.nef
-rw-rw-r--  1 tim  staff    0 Jun 13 08:03 foo3.nef
-rw-rw-r--  1 tim  staff    0 Jun 13 08:03 foo5.nef

$ cd nefdir/
$ mkdir newdir/

$ for f in *.nef; do g=${f%.nef}; h=$g.jpeg; echo mv ../jpegdir/$h ./newdir; done
mv ../jpegdir/foo2.jpeg ./newdir
mv ../jpegdir/foo3.jpeg ./newdir
mv ../jpegdir/foo5.jpeg ./newdir