小编典典

在Linux终端中比较两个文件

linux

有两个名为 “ a.txt”“ b.txt”的文件 ,都有一个单词列表。现在,我要检查 “ a.txt”中
哪些单词是多余的,而 “ b.txt”中 哪些单词不是。

我需要一种有效的算法,因为我需要比较两个字典。


阅读 383

收藏
2020-06-07

共1个答案

小编典典

这是我的解决方案:

mkdir temp
mkdir results
cp /usr/share/dict/american-english ~/temp/american-english-dictionary
cp /usr/share/dict/british-english ~/temp/british-english-dictionary
cat ~/temp/american-english-dictionary | wc -l > ~/results/count-american-english-dictionary
cat ~/temp/british-english-dictionary | wc -l > ~/results/count-british-english-dictionary
grep -Fxf ~/temp/american-english-dictionary ~/temp/british-english-dictionary > ~/results/common-english
grep -Fxvf ~/results/common-english ~/temp/american-english-dictionary > ~/results/unique-american-english
grep -Fxvf ~/results/common-english ~/temp/british-english-dictionary > ~/results/unique-british-english
2020-06-07