title: In shell, how do I delete numbered duplicate files?
body: <p>I've got a directory with a few thousand files in it, named things like:</p>
  
  <pre><code>filename.ext
  filename (1).ext
  filename (2).ext
  otherfile.ext
  otherfile (1).ext
  etc.
  </code></pre>
  
  <p>Most of the files with bracketed numbers are duplicates of the original, but in some cases they're not.</p>
  
  <p>How can I keep my original files, delete the duplicates, but not lose the files that are different?</p>
  
  <p>I know that I could <code>rm *\).ext</code>, but that obviously doesn't make sure that files match the original.</p>
  
  <p>I'm using OS X, so I have a <code>md5</code> program that functions sort of like <code>md5sum</code> in Linux, though it puts the hash at the end of the line instead of the beginning.  I was thinking I could use an awk script to take the output of <code>md5 *.ext | awk 'some script'</code>, find duplicates by md5, and delete them, but the command line is too long (<code>bash: /sbin/md5: Argument list too long</code>).</p>
  
  <p>And I don't know what to write in the script.  I was thinking of storing things in an array with this:</p>
  
  <pre><code>awk '{a[$NF]++} a[$NF]&gt;1{sub(/).*/,""); sub(/.*(/,""); system("rm " $0);}'
  </code></pre>
  
  <p>But that always seems to delete my original.</p>
  
  <p>What am I doing wrong?  How do I do it right?</p>
  
  <p>Thanks.</p>