linux - 获取文本文件中单词列表的字典定义的最简单方法

标签 linux unix dictionary awk cat

文件1:

hello
world

我不知道从文本文件中提取单词列表、找到它们的定义并将它们粘贴到输出文本文件中的最佳方法。我一直在考虑使用 WordNet - 但不知道如何使该过程自动化。

有没有人有任何想法(也许是 google/APIs/linux 应用程序)可以用来查找单词的定义,然后将它们粘贴到文本文件中?

文件2:

an expression of greeting; "every morning they exchanged polite hellos" 
universe: everything that exists anywhere; "they study the evolution of the universe"; "the biggest tree in existence"

最佳答案

虽然 API 或库可能是解决之道(here 是一些 Perl 的东西),但下面的 Bash 脚本非常可能会给您一些想法:

saveIFS="$IFS"
for w in hello goodbye bicycle world
do
    echo
    echo "------- $w -------"
    def=$(wn $w -over)
    IFS=$'\n'
    for line in $def
    do
        echo -e "\t${line}"
        IFS="$saveIFS"
        if [[ $line =~ ^[[:digit:]]*\. ]]
        then 
            for word in $line
            do
                echo -e "\t\t${word%*[,;]}"
            done
        fi
    done
    IFS="$saveIFS"
done

如果文件中有一个单词列表,一个单词一行,将上面脚本的第一行 for 和最后一行 done 更改为:

while read -r w
    # . . .
done < wordlist

关于linux - 获取文本文件中单词列表的字典定义的最简单方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1599116/

相关文章:

linux - 通过shell脚本将参数添加到conf文件中

c++ - 数误差的质因数分解

python - 字典每个键分为多行

c - 我需要有关为微 Controller 编写设备驱动程序的信息

python - 如何为子进程注册信号处理程序?

c - 直到程序结束,文件才写入磁盘

c++ - C++ 中的多重映射

python - 如何从 tmux session 中获取标准输出和标准错误?

linux - 如何创建类似 $RANDOM 的 bash 变量

linux - git 子模块 : ln -s