这是使用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 :(得分:0)
我相信,如果你改变sed -e
做s/^.*S:/ /
或者更加谨慎,s/^[^S]*S://
你会得到你想要的。如果sed命令替换了一个标签(我无法分辨),那么你可能想保留那个......
答案 1 :(得分:0)
我不知道grep "*"
打算做什么,但您可以将其更改为:
grep -Eo '\(.*'
答案 2 :(得分: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 ****
行。