我是靠谱客的博主 友好狗,这篇文章主要介绍linux 操作系统 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开头的行看起来是连续重复的行。

最后

以上就是友好狗最近收集整理的关于linux 操作系统 uniq命令的说明和使用的全部内容,更多相关linux内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(278)

评论列表共有 0 条评论

立即
投稿
返回
顶部