removelink.sh

 

##!/usr/bin
 ###
 ### removelink.sh
 ###
 ### Loop through every HTML file
 ### removing link
 ###
 ###
 
if [ $# -lt 2 ]; then
   echo "Usage: removelink.sh url phrase"
   echo " "
   echo "For example "
   echo " removelink.sh www.setgetweb.com/java/exceptions.html#throwable   throwable "
   echo " "
   exit
else
   url=$1
   key1=$2
   key2=$3
   key3=$4
   key4=$5
   key5=$6

fi

 phrase=$key1

 if [ "$key2" != "" ]
 then
    phrase="${key1} ${key2}"
 fi

 if [ "$key3" != "" ]
 then
    phrase="${key1} ${key2} ${key3}"
 fi

 if [ "$key4" != "" ]
 then
    phrase="${key1} ${key2} ${key3} ${key4}"
 fi

 if [ "$key5" != "" ]
 then
    phrase="${key1} ${key2} ${key3} ${key4} ${key5}"
 fi

echo "Replacing $url with $phrase"

 
 for i in `find . -name \*.htm* -print`
 do
    if  `grep $url $i >/dev/null 2>/dev/null` 
    then
       echo "Updating $i"
       sed "s,<a href=\"http://$url\">$phrase</a>,$phrase,g" $i > $i.tmp
       mv $i.tmp $i
       chmod 777 $i
    fi
 done