如何在两个文件中搜索重复的用户,然后打印这些行?
我有两个文件:FILE1 和 FILE2: 文件1:
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 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
FILE2
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
OUTPUT FILE
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
I tried with a for loop but with particular succes..
Can anyone write me a code for this?
Thx!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可能会遗漏一些东西,但我认为“某种独特”应该给出正确的答案。
当然,除非您提供的输出文件是您期望的整个输出。由于您没有提及有关从输出中消除行的任何内容,因此我假设您想要所有这些行。
I might be missing something, but I'd think a "sort unique" should give the right answer.
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.
请务必先放置较大的文件,在本例中它是
file2
概念验证
或者,您可以使用它,但它需要两次调用
awk
,因此不像性能快:Be sure to put the larger file first, in this case it was
file2
Proof of Concept
Alternatively, you can use this but it requires two calls to
awk
and is thus not as fast in performance: