find lines from one file in another

独自空忆成欢 提交于 2019-12-02 02:19:21

If file1.txt and file2.txt are sorted, you could use 'comm'

comm -12 file1.txt file2.txt > newlist.txt

If each the names in each list are unique, then you can find their intersection as follows:

sort file1.txt file2.txt | uniq -d > newlist.txt

Your grep -f file1.txt file2.txt > newlist.txt is a nice thought, but will give too much hits when file1.txt has "s10" and file2.txt has "slass100". You want to match the complete line, so try

grep -Fxf file1.txt file2.txt > newlist.txt

This should be faster than a solution that requires sorting first.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!