title: Remove duplicate jars in a directory
body: <p>I have a script to remove lower version jars files in a directory.</p>
  
  <pre class="lang-sh prettyprint-override"><code>#!/bin/bash
  #Script to remove lower version jar files.
  
  for PREFIX in `ls *.jar|sed 's/-[0-9\.\0-9\.a-zA-Z]*\.jar//g'|uniq -d`; do
    for FILE in `ls -r ${PREFIX}*|sed '1d'`; do
      echo " $FILE"
      rm $FILE
    done
  done
  </code></pre>
  
  <p>It has a bug.</p>
  
  <p>I have below list of Duplicate jar files in a directory.</p>
  
  <pre><code>xyz-1.1.jar
  xyz-1.1.1.jar
  abc-1.6.jar
  abc-1.3.jar
  abc-xyz-pqr-1.9.6.jar
  abc-xyz-pqr-1.9.2.jar
  xyz-tom.jar
  xyz-tom-20120423.jar
  xyz-tom-20120410.jar
  abc-toolkit-1.6-runtime-5.2.0.jar
  abc-toolkit-1.6-runtime-5.0.0.jar
  </code></pre>
  
  <p>The bug is with xyz pattern jar files.
  BUG: </p>
  
  <ul>
  <li>Script is removing xyz-1.1.1.jar file instead of xyz-1.1.jar</li>
  <li>Script is removing xyz-tom-20120423.jar and xyz-tom-20120410.jar files.</li>
  </ul>