: ########################################################################## # Title : synonym - show synonyms for words # Author : Heiner Steven # Date : 1999-12-09 # Requires : geturl, striphtml, urlencode # Category : WWW # SCCS-Id. : @(#) synonym 1.3 14/09/08 ########################################################################## # Description # ########################################################################## PN=`basename "$0"` # Program name VER='1.3' THES_URL=http://www.merriam-webster.com/thesaurus Usage () { echo >&2 "$PN - show synonyms for words, $VER usage: $PN word [word ...] Uses the thesaurus at $POSTURL" exit 1 } Msg () { for MsgLine do echo "$PN: $MsgLine" >&2 done } Fatal () { Msg "$@"; exit 1; } while getopts :h opt do case "$opt" in # your flags here h) Usage;; \?) Usage;; esac done shift `expr $OPTIND - 1` [ $# -ge 1 ] || Usage error=0 for word do encoded=`echo "$word" | urlencode` geturl "$THES_URL/$encoded" | sed 's|
|
\n|g' | striphtml | awk ' found && $1 == "Synonyms" { $1 = "" print "'"$word"':" $0 exit(0) } /^'"$word"'/ { found = 1 } ' | grep . if [ $? -ne 0 ] then Msg "no results for $word" error=1 fi done exit $error