How to find words from one file in another file?

后端 未结 2 1949
予麋鹿
予麋鹿 2020-12-11 17:02

In one text file, I have 150 words. I have another text file, which has about 100,000 lines.

How can I check for each of the words belonging to the first file wh

2条回答
  •  既然无缘
    2020-12-11 17:08

    You can use grep -f:

    grep -Ff "first-file" "second-file"
    

    OR else to match full words:

    grep -w -Ff "first-file" "second-file"
    

    UPDATE: As per the comments:

    awk 'FNR==NR{a[$1]; next} ($1 in a){delete a[$1]; print $1}' file1 file2
    

提交回复
热议问题