#/usr/bin/ksh ### link.sh ### ### Usage: ### ### link.sh linkdir file.html phrase ### ### Create link to file.html in all html files under linkdir that have phrase ### Run this from the directory where file.html is located ### ### if [ "$3" = "" ] then echo "Usage: $0 linkdir filename phrase" exit 1 fi linkdir=$1 file=$2 key1=$3 key2=$4 key3=$5 key4=$6 key5=$7 key6=$8 key7=$9 path=`pwd | sed "s,/var/www,," | sed "s,/,/,g"` 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 if [ "$key6" != "" ] then phrase="${key1} ${key2} ${key3} ${key4} ${key5} ${key6}" fi if [ "$key7" != "" ] then phrase="${key1} ${key2} ${key3} ${key4} ${key5} ${key6} ${key7} " fi if [ "$key8" != "" ] then phrase="${key1} ${key2} ${key3} ${key4} ${key5} ${key6} ${key7} ${key8} " fi echo "Looking for $grep" for i in `find $linkdir -name \*.htm\* -print | egrep -v "/$file | egrep -v javadoc" ` do ib=`basename $i` if [ "$ib" = "$file" ] then echo "$ib = $file, skipping" continue fi if `egrep -l "$grep" $i >/dev/null 2>/dev/null` then atag=`/usr/local/bin/atag.sh $i $grep` if `echo $atag | egrep 1 >/dev/null 2>/dev/null` then echo "disqualified atag" continue fi # Atag=`/usr/local/bin/Atag.sh $i $grep` # if `echo $Atag | egrep 1 >/dev/null 2>/dev/null` # then # echo "disqualified Atag" # continue # fi titletag=`/usr/local/bin/titletag.sh $i $grep` if `echo $titletag | egrep 1 >/dev/null 2>/dev/null` then echo "disqualified titletag" continue fi h1tag=`/usr/local/bin/h1tag.sh $i $grep` if `echo $h1tag | egrep 1 >/dev/null 2>/dev/null` then echo "disqualified h1tag" continue fi h2tag=`/usr/local/bin/h2tag.sh $i $grep` if `echo $h2tag | egrep 1 >/dev/null 2>/dev/null` then echo "disqualified h2tag" continue fi h3tag=`/usr/local/bin/h3tag.sh $i $grep` if `echo $h3tag | egrep 1 >/dev/null 2>/dev/null` then echo "disqualified h3tag" continue fi h4tag=`/usr/local/bin/h4tag.sh $i $grep` if `echo $h4tag | egrep 1 >/dev/null 2>/dev/null` then echo "disqualified h4tag" continue fi # tabletag=`/usr/local/bin/tabletag.sh $i $grep` # if `echo $tabletag | egrep 1 >/dev/null 2>/dev/null` # then # echo "disqualified tabletag" # continue # fi imgtag=`/usr/local/bin/imgtag.sh $i $grep` if `echo $imgtag | egrep 1 >/dev/null 2>/dev/null` then echo "disqualified imgtag" continue fi xfile=`echo $file | sed "s/\////g"` p="http://www.setgetweb.com${path}/${xfile}" echo " " echo "Creating link in:" echo " $i" echo " " echo "using the phrase: " echo " $grep" echo " " ### ### Here is the compromise syntax ### sed "s/ $grep / <a href=\"$p\">$phrase<\/a> /" $i | \ sed "s/ $grep\./ <a href=\"$p\">$phrase<\/a>\./" | \ sed "s/ $grep,/ <a href=\"$p\">$phrase<\/a>\,/" | \ sed "s/ $grep,/ <a href=\"$p\">$phrase<\/a>\,/" | \ sed "s/($grep)/(<a href=\"$p\">$phrase<\/a>)/" | \ sed "s/($grep\./(<a href=\"$p\">$phrase<\/a>./" | \ sed "s/ $grep(/ <a href=\"$p\">$phrase<\/a>(/" | \ sed "s/($grep /(<a href=\"$p\">$phrase<\/a> /" | \ sed "s/ $grep$/ <a href=\"$p\">$phrase<\/a>/" | \ sed "s/ $grep:/ <a href=\"$p\">$phrase<\/a>:/" | \ sed "s/ $grep;/ <a href=\"$p\">$phrase<\/a>;/" | \ sed "s/^$grep$/<a href=\"$p\">$phrase<\/a>/" | \ sed "s/^$grep /<a href=\"$p\">$phrase<\/a> /" | \ sed "s/\.$grep;/\.<a href=\"$p\">$phrase<\/a>;/" | \ sed "s/>$grep<\/td>/><a href=\"$p\">$phrase<\/a><\/td>/" | \ sed "s/top>$grep$/top><a href=\"$p\">$phrase<\/a>/" | \ sed "s/ $grep<\/td>/ <a href=\"$p\">$phrase<\/a><\/td>/" | \ sed "s/<dt>$grep<\/dt>/<dt><a href=\"$p\">$phrase<\/a><\/dt>/" | \ sed "s/a>$grep/a><a href=\"$p\">$phrase<\/a>/" | \ sed "s/top>$grep /top><a href=\"$p\">$phrase<\/a> /" | \ sed "s/<B>$grep<\/B>/<a href=\"$p\">$phrase<\/a>/" | \ sed "s/<b>$grep<\/b>/<a href=\"$p\">$phrase<\/a>/" | \ sed "s/<br>$grep/<br><a href=\"$p\">$phrase<\/a>/" | \ sed "s/<pre>$grep/<pre><a href=\"$p\">$phrase<\/a>/" | \ sed "s/<p>$grep /<p><a href=\"$p\">$phrase<\/a> /" | \ sed "s/<p>$grep<\/p>/<p><a href=\"$p\">$phrase<\/a><\/p>/" | \ sed "s/<li>$grep/<li><a href=\"$p\">$phrase<\/a>/" | \ sed "s/<code>$grep<\/code>/<a href=\"$p\">$phrase<\/a>/" | \ sed "s/ $grep=/ <a href=\"$p\">$phrase<\/a>=/" | \ sed "s/^$grep=/<a href=\"$p\">$phrase<\/a>=/" | \ sed "s/<tt>$grep<\/tt>/<a href=\"$p\">$phrase<\/a>/" | \ sed "s/<em>$grep<\/em>/<a href=\"$p\">$phrase<\/a>/" | \ sed "s/<i>$grep<\/i>/<a href=\"$p\">$phrase<\/a>/" | \ sed "s/<tt>$grep<\/tt>/<a href=\"$p\">$phrase<\/a>/" | \ sed "s/;$grep>/;<a href=\"$p\">$phrase<\/a>>/" | \ sed "s/;$grep /;<a href=\"$p\">$phrase<\/a> /" | \ sed "s/{$grep}/{<a href=\"$p\">$phrase<\/a>}/" | \ sed "s/{$grep /{<a href=\"$p\">$phrase<\/a> /" | \ sed "s/ $grep}/ <a href=\"$p\">$phrase<\/a>}/" | \ sed "s/\$grep/\$<a href=\"$p\">$phrase<\/a>/" | \ sed "s///\//g" > tmp.$$ mv -f tmp.$$ $i ### Enable SSI chmod 777 $i fi ### sed "s/($grep)/(<a href=\"$p\">$phrase<\/a>)/" | \ ### sed "s/($grep /(<a href=\"$p\">$phrase<\/a> /" | \ ### sed "s/lt;$grep /lt;<a href=\"$p\">$phrase<\/a> /" $i | \ ### sed "s/lt;$grep\//lt;<a href=\"$p\">$phrase<\/a>\//g" | \ ### sed "s/lt;$grep$/lt;<a href=\"$p\">$phrase<\/a>/" | \ ### sed "s/lt;$grep>/lt;<a href=\"$p\">$phrase<\/a>>/" | \ ### sed "s/lt;\/$grep>/lt;\/<a href=\"$p\">$phrase<\/a>>/" | \ ### sed "s/ $grep\,/ <a href=\"$p\">$phrase<\/a>\,/" | \ ### sed "s/ $grep)/ <a href=\"$p\">$phrase<\/a>)/" | \ done