Linux uniq命令
Linux uniq命令用于删除文件中的重复行,它忽略文件中的空白行,只对非空行进行处理。
使用方法
uniq 命令的基本格式如下:
uniq [OPTION]... [INPUT [OUTPUT]]
其中,选项可以是:
- -c:在每一行前面加上该行在文件中出现的次数。
- -d:只显示重复出现的行。
- -u:只显示不重复出现的行。
示例:查看当前目录下的文件test.txt,内容如下:
hello world hello linux
使用uniq命令删除重复行:
$ uniq test.txt hello world linux
使用-d选项只显示重复出现的行:
$ uniq -d test.txt hello
使用-u选项只显示不重复出现的行:
$ uniq -u test.txt world linux
使用-c选项在每一行前面加上该行在文件中出现的次数:
$ uniq -c test.txt 2 hello 1 world 1 linux