Comment utiliser Google comme base de données dans le dictionnaire via bash? Comment saisir la première définition?

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

Question

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

Décharge toute une série de définitions de google.com. Vous trouverez un exemple ci-dessous:

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"

En fait, je ne veux pas toutes les définitions, juste la première:

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

Comment peut-on extraire cette phrase de la sortie? C'est entre deux *, cela pourrait-il être utilisé?

Était-ce utile?

La solution

Ceci supprimera la puce au début de la première ligne, l’imprimera et supprimera le reste de la sortie.

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

Autres conseils

Ajouter ceci:

head -n 1 -q | tail -n 1

Donc ça devient:

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

essayez la commande principale

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top