'\" te .\" Copyright (c) 2007, 2011, Oracle and/or its affiliates.All rights reserved. .\" Copyright 1989 AT&T .\" Portions Copyright (c) 1982-2007 AT&T Knowledge Ventures .\" Copyright (c) 1992, X/Open Company Limited All Rights Reserved .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation.Original documentation from The Open Group can be obtained online at http://www.opengroup.org/bookstore/. .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation.In the following statement, the phrase "this text" refers to portions of the system documentation.Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group.In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document.The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.This notice shall appear on any product containing this material. .TH uniq 1 "2011 年 7 月 28 日" "SunOS 5.11" "用户命令" .SH 名称 uniq \- 报告或过滤出文件中重复的行 .SH 用法概要 .LP .nf \fB/usr/bin/uniq\fR [\fB-c\fR | \fB -d \fR | \fB -u \fR] [\fB -f \fR \fIfields\fR] [\fB-s\fR \fIchar\fR] [\fIinput_file\fR [\fIoutput_file\fR]] .fi .LP .nf \fB/usr/bin/uniq\fR [\fB-c\fR | \fB -d \fR | \fB -u \fR] [\fB-\fR\fIn\fR ] [\fB+\fR\fIm\fR ] [\fIinput_file\fR [\fIoutput_file\fR]] .fi .SH 描述 .sp .LP \fBuniq\fR 可以读取输入、比较相邻的行并将每个输入行的一个副本写入输出。不会写入重复相邻行的第二个及以后的副本。 .sp .LP 如果未指定输出文件 \fIoutput_file\fR,\fBuniq\fR 将写入标准输出。如果未指定 \fIinput_file\fR 或者 \fIinput_file\fR 为 \fB-\fR,\fBuniq\fR 将从标准输入读取,并将文件开头定义为当前偏移。 .SH 选项 .sp .LP 支持以下选项: .sp .ne 2 .mk .na \fB\fB-c\fR\fR .ad .RS 6n .rt 在每个输出行前面添加该行在输入中出现次数的计数。 .RE .sp .ne 2 .mk .na \fB\fB-d\fR\fR .ad .RS 6n .rt 不写入输入中不重复的行。 .RE .sp .ne 2 .mk .na \fB\fB-f\fR\fR .ad .br .na \fB\fR .ad .RS 6n .rt 进行比较时,忽略每个输入行中的第一个 \fIfields\fR \fIfields\fR(\fIfields\fR 是一个十进制正整数)。\fIfield\fR 是符合以下基本正则表达式的最大字符串: .sp .in +2 .nf [[:blank:]]*[^[:blank:]]* .fi .in -2 .sp 如果 \fIfields\fR 指定的 \fIfields\fR 多于输入行中出现的数目,则使用空字符串进行比较。 .RE .sp .ne 2 .mk .na \fB\fB-s\fR\fR .ad .RS 6n .rt 进行比较时,忽略第一个 chars 字符(chars 是一个十进制正整数)。如果与 \fB-f\fR 选项一起指定,将忽略第一个 \fIfields\fR \fIfields\fR 后面的第一个 chars 字符。如果 chars 指定的字符多于输入行中存在的数目,则使用空字符串进行比较。 .RE .sp .ne 2 .mk .na \fB\fB-u\fR\fR .ad .RS 6n .rt 不写入输入中重复的行。 .RE .sp .ne 2 .mk .na \fB\fB-\fR\fIn\fR\fR .ad .RS 6n .rt 等效于将 \fIfields\fR 设置为 \fIn\fR 时的 \fB-f\fR \fIfields\fR。 .RE .sp .ne 2 .mk .na \fB\fB+\fR\fIm\fR\fR .ad .RS 6n .rt 等效于将 \fIchars\fR 设置为 \fIm\fR 时的 \fB-s\fR \fIchars\fR。 .RE .SH 操作数 .sp .LP 支持下列操作数: .sp .ne 2 .mk .na \fB\fIinput_file\fR\fR .ad .RS 15n .rt 输入文件的路径名。如果未指定 \fIinput_file\fR 或者 \fIinput_file\fR 为 \fB-\fR,则使用标准输入。 .RE .sp .ne 2 .mk .na \fB\fIoutput_file\fR\fR .ad .RS 15n .rt 输出文件的路径名。如果未指定 \fIoutput_file\fR,则使用标准输出。如果 \fIoutput_file\fR 指定的文件是 \fIinput_file\fR 指定的文件,则产生的结果不确定。 .RE .SH 示例 .LP \fB示例 1 \fR使用 \fBuniq\fR 命令 .sp .LP 以下示例将列出 \fBuniq.test\fR 文件的内容,并输出重复行的一个副本。 .sp .in +2 .nf example% \fBcat uniq.test\fR This is a test. This is a test. TEST. Computer. TEST. TEST. Software. example% \fBuniq -d uniq.test\fR This is a test. TEST. example% .fi .in -2 .sp .sp .LP 接下来这个示例仅输出 \fBuniq.test\fR 文件中不重复的行。 .sp .in +2 .nf example% \fBuniq -u uniq.test\fR TEST. Computer. Software. example% .fi .in -2 .sp .sp .LP 最后一个示例输出一份报告,每一行前面有该行在文件中出现次数的计数: .sp .in +2 .nf example% \fBuniq -c uniq.test\fR 2 This is a test. 1 TEST. 1 Computer. 2 TEST. 1 Software. example% .fi .in -2 .sp .SH 环境变量 .sp .LP 有关影响 \fBuniq\fR 执行的环境变量 \fBLANG\fR、\fBLC_ALL\fR、\fBLC_CTYPE\fR、\fBLC_MESSAGES\fR 和 \fBNLSPATH\fR 的说明,请参见 \fBenviron\fR(5)。 .SH 退出状态 .sp .LP 将返回以下退出值: .sp .ne 2 .mk .na \fB\fB0\fR\fR .ad .RS 6n .rt 成功完成。 .RE .sp .ne 2 .mk .na \fB\fB>0\fR\fR .ad .RS 6n .rt 出现错误。 .RE .SH 属性 .sp .LP 有关下列属性的说明,请参见 \fBattributes\fR(5): .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . 属性类型属性值 _ 可用性system/core-os _ CSIEnabled(已启用) _ 接口稳定性Committed(已确定) _ 标准请参见 \fBstandards\fR(5)。 .TE .SH 另请参见 .sp .LP \fBcomm\fR(1)、\fBpack\fR(1)、\fBpcat\fR(1)、\fBsort\fR(1)、\fBuncompress\fR(1)、\fBattributes\fR(5)、\fBenviron\fR(5)、\fBstandards\fR(5)