这是使用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"
有帮助吗?

解决方案 3

我有一段代码工作,它增加了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 **** 行。

其他提示

我相信如果你改变 sed -e 去做 s /^.* S:/ / 或者或许,要特别小心, s / ^ [^ S] * S:// 你会得到你想要的。如果sed命令替换了一个标签(我无法分辨),那么你可能想保留那个......

我不知道 grep" *" 的目的是什么,但您可以将其更改为:

grep -Eo '\(.*'
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top