开发者

Using google as a dictionary lookup via bash, How can one grab the first definition?

#!/bin/bash
# Command line look up u开发者_Python百科sing Google's define feature - command line dictionary

echo "Type in your word:"
read word

/usr/bin/curl -s -A 'Mozilla/4.0'  'http://www.google.com/search?q=define%3A+'$word \
| html2text -ascii -nobs -style compact -width 500 | grep "*"

Dumps a whole series of definitions from google.com an example is below:

Type in your word:
world
    * universe: everything that exists anywhere; "they study the evolution of the universe"; "the biggest tree in existence"
    * people in general; especially a distinctive group of people with some shared interest; "the Western world"
    * all of your experiences that determine how things appear to you; "his world was shattered"; "we live in different worlds"; "for them demons were as much a part of reality as trees were"

Thing is, I don't want all the definitions, just the first one:

universe: everything that exists anywhere; "they study the evolution of the universe"; "the biggest tree in existence"

How can a grab that sentence out from the output? Its between two *, could that be used?


This will strip the bullet from the beginning of the first line, printing it and discarding the rest of the output.

sed 's/^ *\* *//; q'


Add this:

head -n 1 -q | tail -n 1

So it becomes:

#!/bin/bash
# Command line look up using Google's define feature - command line dictionary

echo "Type in your word:"
read word

/usr/bin/curl -s -A 'Mozilla/4.0'  'http://www.google.com/search?q=define%3A+'$word \
| html2text -ascii -nobs -style compact -width 500 | grep "*" | head -n 1 -q | tail -n 1


try head command

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜