在Linux终端中比较两个文件

有两个名为 和 ,都有一个单词列表。现在,我要检查

哪些单词是多余的,而 哪些单词不是。

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

回答:

这是我的解决方案:

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

以上是 在Linux终端中比较两个文件 的全部内容, 来源链接: utcz.com/qa/403730.html

回到顶部