Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Script to remove lower version jar files

$
0
0
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
adepu

Viewing all articles
Browse latest Browse all 13329

Trending Articles