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
#! /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
Generally scripts are written based on pattern change. In your requirement on input, only c.jar is taken from path/2/. I have simulated your input to required output.
And, your input and output is not being generallized so that script is given with using speicific filenames.
I dont think sort is a possible soution. The path length varies i.e. the directory structure is different for files. Some of them have a depth of 3.. others a depth of more than 3.