Linux Shell学习:uniq命令使用方法介绍

资讯 驱动中国 196 次阅读 0 条评论
分享 Q
 

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开头的行看起来是连续重复的行。

LinuxShell学习:uniq命令使用方法介绍 学习Li
版权声明:本文由驱动中国整理发布,转载需注明出处与原文链接。如有疑问请联系 editor@qudong.com
本文价值 成为第一个评分的人
登录后为本文打分
网友评论0 条评论
正在回复 的评论取消
评论加载中…
🔐

登录后参与互动

评论、点赞均可赚积分
连续签到、邀请好友也有奖励 🎁

电脑端: 微信扫码登录 微信内: 一键登录

微信扫一扫

打开微信「扫一扫」,分享本文到朋友圈或好友