linux uniq 命令基本上用于删除文件中所有重复的行。当一行重复多次并用一行替换这些多行时,使用此命令。此命令设计用于 分类 文件夹。
null
目的: 从已排序的“输入文件”中删除重复的行,并将唯一的行发送到“输出文件”。如果未指定“输出文件”,则将命令的输出发送到标准输出。如果未指定“输入文件”,则该命令将从标准输出中获取输入。
语法:
$ uniq [option] [input-file] [output-file]
选项:
-c: 在每个输出行前面加上它出现的次数。 -d: 显示重复的行。 -u: 显示未重复的行。
例如: 创建一个示例输入文件。
$ cat sample
输入: 这是uniq命令的测试文件。 它包含一些重复的行。 它包含一些重复的行。 有些是不同的。 它包含一些重复的行。 它包含一些重复的行。
1.文件未排序时删除重复行。
$ uniq sample
输出: 这是uniq命令的测试文件。 它包含一些重复的行。 有些是不同的。 它包含一些重复的行。
2.排序后删除重复文件。
$ sort sample -> sample1 $ uniq sample1
输出: 有些是不同的。 它包含一些重复的行。 这是uniq命令的测试文件。
3.查找重复行的次数。
$ uniq -c sample1
输出:
1 And some are different. 4 It contains some repeated lines. 1 This is a test file for the uniq command.
4.寻找重复的线条。
$ uniq -d sample1
输出:
It contains some repeated lines.
5.查找唯一的行并存储在另一个文件中。
$ uniq -u sample1 out $ cat out
输出:
And some are different. This is a test file for the uniq command.
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END