I have a list which contains all the jar files shipped with the product I am involved with. Now, in this list I have some jar files which appear again and again. But these jar files are present in different folders.
My input file looks like this
Code:
/path/1/to a.jar
/path/2/to a.jar
/path/1/to b.jar
/path/1/to c.jar
/path/1/to d.jar
/path/2/to c.jar
Now I need to remove the duplicate entries i.e. remove the extra a.jar, c.jar and others like wise.
Final list would be like this:
Code:
/path/1/to a.jar
/path/1/to b.jar
/path/2/to c.jar
/path/1/to d.jar
This is the script I have so far..
Code:
#! /bin/sh
cp jar.txt jarnew.txt
for file in $(cat jar.txt)
do
FILE1=`basename $file`
for dup in $(cat jar.txt)
do
FILE2=`basename $dup`
if [ "$file" != "$dup" -a "$FILE1" == "$FILE2" ] ; then
sed -e '/($dup)/ d' <jarnew.txt >jarnew.txt.tmp
echo "$FILE1 $FILE2"
mv jarnew.txt.tmp jarnew.txt
fi;
done
done
But with this, the main functionality of the script is not working. i.e. the if condition is not working as required. Could be the
sed problem or the logic.
I am getting the jarnew.txt as good as the jar.txt
Any pointers on how to proceed ?
Vino