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 

 boy took bat home 

 girl took bat home 

 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  -s  test  

boy took bat home

-f(跳过的字段)和-s(跳过的字符数)选项忽略每行的前2个字段,忽略第二个空白字符和第三个字段的首字符(从跳过的字段数开始算起,与-f选项配合使用),结果at home

[root@stu100 ~]# uniq -f  test  

boy took bat home  

dog brought hat home

-f选项忽略每行的第一个字段,这样boy ,girl开头的行看起来是连续重复的行。

lxy@lxy-e440:~$ uniq -w  test.txt 

boy took bat home

girl took bat home

dog brought hat home

lxy@lxy-e440:~$ uniq -w  -u test.txt 

girl took bat home

lxy@lxy-e440:~$ uniq -w  -d test.txt 

boy took bat home

dog brought hat home

-w选项对每行第N 个字符以后的内容不作对照

最新文章

  1. 【容器云】十分钟快速构建 Influxdb+cadvisor+grafana 监控
  2. 更改pip源至国内镜像,显著提升下载速度(转载)
  3. git workflow
  4. 日志时间格式有s,ms,us,如何排序最大10行
  5. C#的循环语句练习
  6. json数组和List转换
  7. webstrom插件:如何设置才能让webstrom能提示bootstrap的语法
  8. Project Euler 81:Path sum: two ways 路径和:两个方向
  9. PHP获取当前时间的毫秒数(yyyyMMddHHmmssSSS)
  10. Struts2中将.action改为.do
  11. 可以通过Action来判断是什么操作触发了事件
  12. Programming C#.Inheritance and Polymorphism
  13. vm lxc
  14. poptest老李谈分布式与集群 2
  15. 【Linux学习笔记】关于ubuntu开机菜单栏和任务栏不见了的有效解决方法
  16. Tomcat版本对照表
  17. 【iCore4 双核心板_uC/OS-II】例程四:软件定时器
  18. TCP、UDP网络通信
  19. 【uoj5】 NOI2014—动物园
  20. CloudFlare防护下的破绽:寻找真实IP的几条途径

热门文章

  1. 吴裕雄--天生自然TensorFlow高层封装:Keras-返回值
  2. Debian8.8下的VIM的配置文件
  3. Kubernetes系列:故障排查之Pod状态为CreateContainerError
  4. Java实现生产与消费(完美注释版)
  5. centos6.8 yum安装mysql 5.6
  6. 大道至简伪代码读后感java为代码形式
  7. js几个常用的弹层
  8. [LC] 1002. Find Common Characters
  9. F. Maximum Weight Subset(贪心or树形dp解法)
  10. discount the possibility|pessimistic|bankrupt|