Linux系统中,有两个文件file1和file2,每个文件的每一行都是#UUID,其中的每一UUID表示一个号。要找出在file1中有而在file2中没有的UUID,使用cat,sort,uniq三个命令如何实现

uniq命令的作用:显示唯一的行,对于那些连续重复的行只显示一次!
接下来通过实践实例说明:
[root@stu100 ~]# cat test
boy took bat home
boy took bat home
girl took bat home
dog brought hat home
dog brought hat home
dog brought hat home
test文件的内容,可以看到其中的连续重复行
[root@stu100 ~]# uniq test
boy took bat home
girl took bat home
dog brought hat home
uniq
命令不加任何参数,仅显示连续重复的行一次
[root@stu100 ~]# uniq -c test
2 boy took bat home
1 girl took bat home
3 dog brought hat home
-c
参数显示文件中每行连续出现的次数。
[root@stu100 ~]# uniq -d test
boy took bat home
dog brought hat home
-d
选项仅显示文件中连续重复出现的行。
[root@stu100 ~]# uniq -u test
girl took bat home
-u
选项显示文件中没有连续出现的行。
[root@stu100 ~]# uniq -f 2 -s 2 test
boy took bat home
忽略每行的前2个字段,忽略第二个空白字符和第三个字段的首字符,结果at home
[root@stu100 ~]# uniq -f 1 test
boy took bat home
dog brought hat home
忽略每行的第一个字段,这样boy girl开头的行看起来是连续重复的行。

 

 

[linuxboy823@fedora ~]$ cat file1
1
2
3
4
5
6
[linuxboy823@fedora ~]$ cat file2
1
2
3
4
7
8

[linuxboy823@fedora ~]$ sort file1 file2 |uniq -d>file3


1
、找出file1中有而file2中没有的qq号码


[linuxboy823@fedora ~]$ sort file1 file3|uniq -u
5
6
2
、找出file2中有而file1中没有的qq号码
[linuxboy823@fedora ~]$ sort file2 file3|uniq -u
7
8

3
、找出两个文件中都有的号码
[linuxboy823@fedora ~]$ sort file1 file2 |uniq -d
1
2
3
4

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值