3
#!/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 "*"

google.com から一連の定義全体をダンプします。例を以下に示します。

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"

問題は、すべての定義が必要なわけではなく、最初の定義だけが必要です。

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

出力からその文をどのように取得できますか? その2つの*の間、それは使用できますか?

4

3 に答える 3

2

これにより、最初の行の先頭から箇条書きが取り除かれ、それが印刷され、残りの出力が破棄されます。

sed 's/^ *\* *//; q'
于 2009-10-24T07:04:02.217 に答える
1

これを追加:

head -n 1 -q | tail -n 1

したがって、次のようになります。

#!/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
于 2009-10-24T08:57:06.873 に答える
0

ヘッドコマンドを試す

于 2009-10-24T07:34:23.273 に答える