通过 bash 使用 google 作为字典查找,如何获取第一个定义?
#!/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 "*"
从 google.com 转储一系列定义,示例如下:
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"
事情是,我不需要所有定义,只需要第一个:
universe: everything that exists anywhere; "they study the evolution of the universe"; "the biggest tree in existence"
如何从输出中抓取该句子?两个*之间可以用吗?
#!/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 "*"
Dumps a whole series of definitions from google.com an example is below:
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"
Thing is, I don't want all the definitions, just the first one:
universe: everything that exists anywhere; "they study the evolution of the universe"; "the biggest tree in existence"
How can a grab that sentence out from the output? Its between two *, could that be used?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这将从第一行的开头剥离项目符号,打印它并丢弃其余的输出。
This will strip the bullet from the beginning of the first line, printing it and discarding the rest of the output.
添加这个:
所以它变成:
Add this:
So it becomes:
尝试 head 命令
try head command