Domanda

Ecco uno script da riga di comando per una ricerca nel dizionario usando 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 "*"

Digito " ciao " ecco l'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"

Voglio solo la stringa che sta dopo la S :, niente prima di essa. Voglio rimuovere quanto segue:

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

Lasciando questo per le tubazioni da solo - >

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

Soluzione 3

Ho un pezzo di codice funzionante che si aggiunge alla risposta di 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 "\*\*\*\* "

Rimuove tutta la formattazione che credo. Rimuove anche le righe **** Noun **** .

Altri suggerimenti

Credo che se modifichi quel sed -e per fare s /^.* S: / / o forse, per stare molto attenti, s / ^ [^ S] * S: // otterrai ciò che desideri. Se il comando sed sta sostituendo una scheda (non posso dirlo), potresti voler preservare ...

Non so che cosa intende fare grep " * " , ma puoi cambiarlo in:

grep -Eo '\(.*'
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top