如何在两个文件中搜索重复的用户,然后打印这些行? [英] How to search duplicate users in two files and then print those lines?
本文介绍了如何在两个文件中搜索重复的用户,然后打印这些行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个文件:FILE1 和 FILE2:文件1:
I have two files: FILE1 and FILE2: FILE1:
user1 1.1.1.1
user2 2.2.2.2
user3 3.14.14.3
user4 4.4.4.4
user5 198.222.222.222
文件 2
user1 99.22.54.214
user66 45.22.88.88
user99 44.55.66.66
user4 8.8.8.8
user39 54.54.54.54
user2 2.2.2.2
输出文件
user1 1.1.1.1
user1 99.22.54.214
user2 2.2.2.2
user4 4.4.4.4
user4 8.8.8.8
我尝试了 for 循环,但特别成功.任何人都可以为此写一个代码吗?谢谢!
I tried with a for loop but with particular succes.. Can anyone write me a code for this? Thx!
推荐答案
我可能遗漏了一些东西,但我认为排序独特"应该给出正确的答案.
I might be missing something, but I'd think a "sort unique" should give the right answer.
$ sort -u file1 file2
user1 1.1.1.1
user1 99.22.54.214
user2 2.2.2.2
user3 3.14.14.3
user39 54.54.54.54
user4 4.4.4.4
user4 8.8.8.8
user5 198.222.222.222
user66 45.22.88.88
user99 44.55.66.66
当然,除非您提供的输出文件是您期望的整个输出.由于您没有提及从输出中消除行的任何内容,因此我假设您想要所有这些行.
Unless, of course, the output file you provided is the entire output you expect. Since you didn't say anything about eliminating lines from the output, I'll assume you want all of them.
这篇关于如何在两个文件中搜索重复的用户,然后打印这些行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文