linux - 通过 bash 使用 google 作为字典查找,如何获取第一个定义?

标签 linux command-line dictionary lookup

#!/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"

如何从输出中抓取那句话?介于两个*之间,可以用吗?

最佳答案

这将从第一行的开头去除项目符号,打印它并丢弃其余输出。

sed 's/^ *\* *//; q'

关于linux - 通过 bash 使用 google 作为字典查找,如何获取第一个定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1617152/

相关文章:

ruby-on-rails - 将 Rails 应用程序从 Windows 移植到 Mac 或 Linux

visual-studio - 有什么方法可以从命令行构建 Visual Studio "project only"?

linux - 在 linux 命令历史记录中登录主机名/IP

c - 忽略c文件中的stdio.h文件

linux - 什么文本编辑器与我习惯的控制台命令结合使用

python - 比较 Python 字典中保存的集合

c# - 列表框可以显示字典中的键和值

python - 使用联合将字典添加到 `set()`

linux - 循环 0xb7 汇编但不会链接

command-line - NuGet 如何创建 nuspec 文件