Verwendung von Google als Wörterbuch-Lookup über bash, wie man die erste Definition greifen kann?

StackOverflow https://stackoverflow.com/questions/1617152

Frage

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

Dumps eine ganze Reihe von Definitionen von google.com ein Beispiel unter:

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"

Das Ding ist, ich will nicht alle Definitionen, sondern nur die erste:

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

Wie kann ein Greifer dieser Satz aus dem Ausgang? Sein zwischen zwei *, die verwendet werden könnten?

War es hilfreich?

Lösung

Das wird die Kugel aus dem Anfang der ersten Zeile Streifen, Drucken sie und den Rest des Ausgangs verwerfen.

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

Andere Tipps

Fügen Sie diese:

head -n 1 -q | tail -n 1

So wird es:

#!/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 Kopf Befehl

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top