uniq - 报告或过滤出文件中重复的行
/usr/bin/uniq [ [-c | --count ] |[-d | --repeated ] |[-u | --unique] |[ -D[delimit-method] | --all-repeated [=delimit-method]] ][ -f fields | --skip-fields= fields] [-s chars | --skip-chars=chars][ -w, --check-chars=chars][ -i | --ignore-case] [-z | --zero-terminated][--help] [ input_file [output_file]]
/usr/bin/uniq [ [-c | --count ] |[-d | --repeated ] |[-u | --unique] |[ -D[delimit-method] | --all-repeated[= delimit-method]] ][-w, --check-chars=chars][ -i | --ignore-case] [-z | --zero-terminated][--help][ -n ] [+m ][input_file [output_file]]
uniq 可以读取输入、比较相邻的行并将每个输入行的一个副本写入输出。不会写入重复相邻行的第二个及以后的副本。
如果未指定输出文件 output_file, uniq 将写入标准输出。如果未指定 input_file 或者 input_file 为 -, uniq 将从标准输入读取,并将文件开头定义为当前偏移。
支持以下选项:
在每个输出行前面添加该行在输入中出现次数的计数。
不写入输入中不重复的行。
使用以下分隔方法之一分隔重复行组:
不进行分隔。
在每个组前面附加一个分隔符。
使用分隔符分隔组。
使用空白行进行分隔。
进行比较时,忽略每个输入行中的第一个 fields fields(fields 是一个十进制正整数)。field 是符合以下基本正则表达式的最大字符串:
[[:blank:]]*[^[:blank:]]*
如果 fields 指定的 fields 多于输入行中出现的数目,则使用空字符串进行比较。
进行比较时忽略大小写差异。
进行比较时,忽略第一个 chars 字符(chars 是一个十进制正整数)。如果与 –f 选项一起指定,将忽略第一个 fields fields 后面的第一个 chars 字符。如果 chars 指定的字符多于输入行中存在的数目,则使用空字符串进行比较。
不写入输入中重复的行。
仅比较行中的 char 字符。
使用 0 字节(而非换行符)结束行。
等效于将 fields 设置为 n 时的 –f fields。
等效于将 chars 设置为 m 时的 –s chars。
显示命令用法并退出。
支持下列操作数:
输入文件的路径名。如果未指定 input_file 或者 input_file 为 - ,则使用标准输入。
输出文件的路径名。如果未指定 output_file,则使用标准输出。如果 output_file 指定的文件是 input_file 指定的文件,则产生的结果不确定。
以下示例将列出 uniq.test 文件的内容,并输出重复行的一个副本。
example% cat uniq.test This is a test. This is a test. TEST. Computer. TEST. TEST. Software. example% uniq -d uniq.test This is a test. TEST. example%
接下来这个示例仅输出 uniq.test 文件中不重复的行。
example% uniq -u uniq.test TEST. Computer. Software. example%
最后一个示例输出一份报告,每一行前面有该行在文件中出现次数的计数:
example% uniq -c uniq.test 2 This is a test. 1 TEST. 1 Computer. 2 TEST. 1 Software. example%
有关影响 uniq 执行的以下环境变量的说明,请参见 environ(7):LANG、LC_ALL、LC_CTYPE、LC_MESSAGES 和 NLSPATH。
将返回以下退出值:
成功完成。
出现错误。
有关下列属性的说明,请参见 attributes(7):
|
comm(1)、ypcat(1)、sort(1)、uncompress(1)、attributes(7)、environ(7)、standards(7)