• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

script to remove lower version jars in a directory

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Guys,

I have a script to remove lower version jars files in a directory.


#!/bin/bash
#in a directory full of jar files, it is common to have multiple
#versions of the same jars. If versions are named with only periods
#and alphanumerics, then this groups the jars by the name, deletes
#all the lesser versions

#get a list of jars like x-1.0.0.RELEASE.jar, get only the jar name
#without version or .jar and get only non unique lines (ie., duplicate
#jars are found)
for PREFIX in `ls *.jar|sed 's/-[0-9\.a-zA-Z]*\.jar//g'|uniq -d`; do
echo $PREFIX
#now do a reverse sorted listing with the jar name and remove the
#top line so that non latest versions are returned
for FILE in `ls -r ${PREFIX}*|sed '1d'`; do
echo " $FILE"
rm -f $FILE
done
done



It has a bug and need your help to figure and fix the bug.

Scenario: Assuming i have two jars file in a directory with names xyz-1.1.jar and xyz-1.1.1.jar
This script is deleting xyz-1.1.1.jar (higher version) instead of lower version.

Thanks
Abhee
 
abheeshek reddy
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

abheeshek reddy wrote:hi Guys,

I have a script to remove lower version jars files in a directory.


#!/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




It has a bug and i need your help to figure and fix the bug.

I have below list of Duplicate jar files in a directory.

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

The bug is with xyz pattern jar files.
BUG: 1) Script is removing xyz-1.1.1.jar file instead of xyz-1.1.jar
2) Script is removing xyz-tom-20120423.jar and xyz-tom-20120410.jar files.


Thanks
Abhee

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic