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] [input_file [output_file]]
/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] [-n] [+m][input_file [output_file]]
/usr/bin/uniq --help
uniq 可以读取输入、比较相邻的行并将每个输入行的一个副本写入输出。不会写入重复相邻行的第二个及以后的副本。
如果未指定输出文件 output_file,uniq 将写入标准输出。如果未指定 input_file 或者 input_file 为 -,uniq 将从标准输入读取,并将文件开头定义为当前偏移。
支持以下选项:
在每个输出行前面添加该行在输入中出现次数的计数。
不写入输入中不重复的行。
使用以下分隔方法之一分隔重复行组:
不进行分隔。
在每个组前面附加一个分隔符。
使用分隔符分隔组。
使用空白行进行分隔。
Ignores the first fields fields on each input line when doing comparisons, where fields is a positive decimal integer.field 是符合以下基本正则表达式的最大字符串:
[[:blank:]]*[^[:blank:]]*
If fields specifies more fields than appear on an input line, a null string are used for comparison.
进行比较时忽略大小写差异。
进行比较时,忽略第一个 chars 字符(chars 是一个十进制正整数)。If specified in conjunction with the –f option, the first chars characters after the first fields fields are ignored.If chars specifies more characters than remain on an input line, a null string are used for comparison.
不写入输入中重复的行。
Compare no more than char characters in a line.
使用 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%
See environ(7) for descriptions of the following environment variables that affect the execution of uniq: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES, and NLSPATH.
将返回以下退出值:
成功完成。
出现错误。
有关下列属性的说明,请参见 attributes(7):
|