如何搜索重复的用户在两个文件中,然后打印这些行? [英] How to search duplicate users in two files and then print those lines?

查看:98
本文介绍了如何搜索重复的用户在两个文件中,然后打印这些行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个文件:file1和FILE2:
FILE1:

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循环,但特别更迭..
谁能给我写一个code这个?
THX!

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆