linux的sort 和 uniq 命令
一、sort 命令
二、uniq 命令
可以使用 uniq --h 查看帮助
注意:uniq 只会检测相邻的重复行,如果两行重复但它们位置不相邻,不能检测出来。因此 uniq 常与 sort 搭配使用。
-c 在每行前面显示重复次数
-d 显示重复行
-D 显示所有重复行
-u 仅显示出现一次的行
-i 忽略大小写
例子:cat test.txt (例子内容参考博客https://www.zhukun.net/archives/7294)
this is a test
this is a test
this is a test
i am tank
i love tank
i love tank
this is a test
whom have a try
WhoM have a try
you have a try
i want to abroad
those are good men
we are good men
uniq -c test.txt | sort test.txt | uniq -c |
3 this is a test |
1 i am tank |
sort test.txt | uniq -d | sort test.txt | uniq -D | sort test.txt | uniq -u |
i love tank |
i love tank |
i am tank |
sort test.txt | uniq -ic |
1 i am tank |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步