uniq 作用
通过消除重复的内容,从给定输入(stdin或命令行参数文件)找出单一的行。uniq只能用于排过序的文件,所以uniq经常跟sort一起结合使用。
语法
$ sort unsorted.txt | uniq
示例
$ sort unsorted.txt | uniq 或 $uniq sorted.txt
$ sort unsorted.txt | uniq -c
$ sort unsorted.txt | uniq -d
- d. 使用-s跳过前N个字符,-w指定用于比较的最大字符数
$ sort data.txt | uniq -s 2 -w 2
- e. 跟xargs结合,删除file.txt定义的文件
$ sort file.txt | uniq -z | xargs -0 rm