#-- *--*--*--*--*--*--*--*--*--*--*--*--*-- #-- SCRIPT: #-- tran.sh #-- DESCRIPTION: #-- This script uses the file names of sound files #-- (wav at present) to lookup english translations on #-- on the internet (using wget). #-- The web-site used is #-- http;//www.spanishdict.com/ #-- AUTHOR: #-- mj bishop #-- DATE: #-- may 02 #-- *--*--*--*--*--*--*--*--*--*--*--*--*--*-- if [ -n "$1" ] then sSaveFile=$1 #--rm $sSaveFile else sSaveFile="dict123.txt" # rm dict123.txt fi echo " Starting to translate words [ based on file names ] ... (Saving words & translations ---> $sSaveFile) ----------------------- " for sFile in [a-zA-Z-]*.wav do #-- initialize variables sWord="" sEnglish1="" sEnglish2="" sEnglish3="" iLineCount="" sWord=$(echo $sFile | sed 's/\..*$//g') echo "File Name=$sFile " echo "Word=$sWord " iLineCount=$(cat $sSaveFile | grep "Word=$sWord" | wc -l | tr -d ' ') if [ "$iLineCount" = "0" ] then echo "File Name=$sFile " >> $sSaveFile echo "Word=$sWord " >> $sSaveFile echo "(looking up www.spanishdict.com/ )" #-- Extract the word translations from the #-- returned html page. wget -o temp.txt -O - -nd http://www.spanishdict.com/AS.cfm?e=$sWord | grep -A1 'ED.cfm' | sed -e '/ED\.cfm/d' -e 's/<\/a>//g' > tsave1.txt cat tsave1.txt | expand | sed -e '/\-/d' -e 's/^ *//g' -e 's/ *$//g' > tsave.txt sEnglish1=$(cat tsave.txt | awk 'NR==1') sEnglish2=$(cat tsave.txt | awk 'NR==2') sEnglish3=$(cat tsave.txt | awk 'NR==3') if [ "$sEnglish2" = "$sEnglish1" ] then sEnglish2="" sEnglish3="" fi echo "English1=$sEnglish1" echo "English2=$sEnglish2" echo "English3=$sEnglish3" echo "=" # cat tsave.txt echo "English1=$sEnglish1" >> $sSaveFile echo "English2=$sEnglish2" >> $sSaveFile echo "English3=$sEnglish3" >> $sSaveFile # cat tsave.txt >> $sSaveFile echo "=" >> $sSaveFile else echo 'Word already in save file- not looking up' fi #-- if word already in file #-- Needs more work (disabled now) # if [ "$sEnglish1" = "" ] # then # echo 'looking up www.wordreference.com' # wget -nd -O tsave1.txt -o temp.txt "http://www.wordreference.com/es/en/translation.asp?spen=$sWord" # sEnglish1=$(cat tsave1.txt | grep -A3 'ID="transl1"' | tail -1 | sed -e 's/\([a-zA-Z! ]*\);.*$/\1/g' -e 's/.*<\/i>\([a-zA-Z! ]*\)$/\1/g' -e 's/^ *//g') # fi done #-- Looks up wordreference.com (Harper Collins) very good dictionary # 513 wget -nd -O- 'http://www.wordreference.com/es/en/translation.asp?spen=hijo' | grep -A4 'ID="transl1"' # 523 wget -nd -O- -o temp.txt 'http://www.wordreference.com/es/en/translation.asp?spen=hijo' | grep '> *hijo' | sed -e 's/\([a-zA-Z ]*\);.*$/\1/g' -e 's/.*<\/i>\([a-zA-Z ]*\)$/\1/g' -e 's/^ *//g'