一、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 |