Comparing two files in linux terminal

后端 未结 10 1207
一生所求
一生所求 2020-12-22 17:31

There are two files called \"a.txt\" and \"b.txt\" both have a list of words. Now I want to check which words are extra in \"a.txt\

10条回答
  •  被撕碎了的回忆
    2020-12-22 18:00

    Here is my solution for this :

    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
    

提交回复
热议问题