Question

Here is a command line script for a dictionary lookup using Wordnet:

#!/bin/bash
# Command line look up using Wordnet - command line dictionary

echo "Type in your word:"
read word

/usr/bin/curl -s -A 'Mozilla/4.0'  'http://wordnetweb.princeton.edu/perl/webwn?s='$word'&sub=Search+WordNet&o2=&o0=1&o7=&o5=&o1=1&o6=&o4=&o3=&h=' \
| html2text -ascii -nobs -style compact -width 500 | grep "*"

I type in "hello" here is the output:

Type in your word:
hello
**** Noun ****
    * S:(n)hello, hullo, hi, howdy, how-do-you-do (an expression of greeting) "every morning they exchanged polite hellos"

I only want the string that is after the S:, nothing before it. I want to remove the following:

**** Noun ****
    * S:

Leaving this for piping by itself ->

(n)hello, hullo, hi, howdy, how-do-you-do (an expression of greeting) "every morning they exchanged polite hellos"
Was it helpful?

Solution 3

I've got a piece of code working which adds to the answer of DigitalRoss:

#!/bin/bash
# Command line look up using Wordnet - command line dictionary

echo "Type in your word:"
read word

/usr/bin/curl -s -A 'Mozilla/4.0'  'http://wordnetweb.princeton.edu/perl/webwn?s='$word'&sub=Search+WordNet&o2=&o0=1&o7=&o5=&o1=1&o6=&o4=&o3=&h=' \
| html2text -ascii -nobs -style compact -width 500 | grep "*" | sed 's/^[^S]*S://' | grep -v "\*\*\*\* "

It removes all the formatting I believe. It removes the **** Noun **** lines as well.

OTHER TIPS

I believe that if you alter that sed -e to do s/^.*S:/ / or perhaps, to be extra careful, s/^[^S]*S:// you will get what you want. If the sed command is substituting a tab (I can't tell) then you may want to preserve that...

I don't know what the grep "*" is intended to do, but you could change it to:

grep -Eo '\(.*'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top