2009-10-24 43 views
0

这里文本的仅仅一个特定的行是使用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 "*" 

我在键入“你好”这里是输出:

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" 

我只想要S之后的字符串,没有任何字符。我想删除以下内容:

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

自行离开这个管路 - >

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

回答

0

我有一段代码工作的,这增加了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 "\*\*\*\* " 

它会删除所有的格式,我相信。它也删除了**** Noun ****行。

0

我相信,如果你改变这种sed -es/^.*S:/ /或许,要格外小心,s/^[^S]*S://你会得到你想要的。如果sed命令替换选项卡(我无法说出),那么您可能想保留该选项卡...

+0

删除S :,但不包含****名词****。 – user191960 2009-10-24 05:52:40

0

我不知道grep "*"打算做什么,但可以将其更改为:

grep -Eo '\(.*' 
+0

grep“*” - 从站点抓取定义 - 否则您抓取标头 - 或其他无用的信息。 – user191960 2009-10-24 09:15:20