'\" te .\" Copyright 1989 AT&T .\" Copyright (c) 2009, 2011, Oracle and/or its affiliates.All rights reserved. .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved .\" Portions Copyright (c) 1982-2007 AT&T Knowledge Ventures .\" 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 cut 1 "2011 年 7 月 26 日" "SunOS 5.11" "用户命令" .SH 名称 cut \- 从文件的每个行中剪切选定的字段 .SH 用法概要 .LP .nf \fB/usr/bin/cut\fR \fB-b\fR \fIlist\fR [\fB-n\fR] [\fIfile\fR]... .fi .LP .nf \fB/usr/bin/cut\fR \fB-c\fR \fIlist\fR [\fIfile\fR]... .fi .LP .nf \fB/usr/bin/cut\fR \fB-f\fR \fIlist\fR [\fB-d\fR \fIdelim\fR] [\fB-s\fR] [\fIfile\fR]... .fi .SH 描述 .sp .LP \fBcut\fR 从一个或多个文件中剪切字节、字符或者以字符分隔的字段,并在标准输出上将其串联起来。 .sp .LP \fIoption\fR 参数列表是以逗号或空格分隔的正数和范围的列表。范围可以采用三种形式。第一种是以连字符分隔的两个正整数 (low-high),这表示从 low 到 high 的所有字段。第二种是前面带有连字符的一个正数 (\fB-\fIhigh\fR\fR),这表示从字段 1 到 high 的所有字段。第三种是后面跟有连字符的一个正数 (\fIlow\fR\fB-\fR),这表示从 low 到最后一个字段的所有字段(包括两者)。list 中的元素可以重复,可以交迭,并且可以按任何顺序出现。输出顺序与输入顺序相同。 .sp .LP 必须指定并且只能指定 \fB-b\fR、\fB-c\fR 和 \fB-f\fR 选项中的一个。 .sp .LP 如果未指定 file 或者 file 为 \fB-\fR,则 \fBcut\fR 将从标准输入进行剪切。文件的开头被定义为当前偏移。 .SH 选项 .sp .LP 支持以下选项: .sp .ne 2 .mk .na \fB\fB-b\fR \fIlist\fR\fR .ad .sp .6 .RS 4n 跟在 \fB-b\fR 后的 \fIlist\fR 指定字节位置(例如,\fB-b1-72\fR 将传递每行的前 \fB72\fR 个字节)。当同时使用了 \fB-b\fR 和 \fB-n\fR 时,将对 \fIlist\fR 进行调整以便不拆分多字节字符。 .RE .sp .ne 2 .mk .na \fB\fB-c\fR \fIlist\fR\fR .ad .sp .6 .RS 4n 跟在 \fB-c\fR 后的 list 指定字符位置(例如,\fB-c1-72\fR 将传递每行的前 \fB72\fR 个字符)。 .RE .sp .ne 2 .mk .na \fB\fB-d\fR \fIdelim\fR\fR .ad .sp .6 .RS 4n 跟在 \fB-d\fR 后的字符是字段分隔符(仅限 \fB-f\fR 选项)。缺省值为 TAB。空格或者对 shell 而言具有特殊含义的其他字符必须用引号括起来。\fIdelim\fR 可以是多字节字符。 .RE .sp .ne 2 .mk .na \fB\fB-f\fR \fIlist\fR\fR .ad .sp .6 .RS 4n 跟在 \fB-f\fR 后的 \fIlist\fR 是所采用的在文件中由某个分隔符分隔的字段的列表(请参见 \fB-d\fR);例如,\fB-f1,7\fR 将仅复制第一个和第七个字段。没有字段分隔符的行将原样传递(适合用于表格的小标题),除非指定了 \fB-s\fR。 .RE .sp .ne 2 .mk .na \fB\fB-n\fR\fR .ad .sp .6 .RS 4n 不拆分字符。当同时使用了 \fB-b\fR list 和 \fB-n\fR 时,将对 \fIlist\fR 进行调整以便不拆分多字节字符。 .RE .sp .ne 2 .mk .na \fB\fB-s\fR\fR .ad .sp .6 .RS 4n 当使用了 -f 选项时,将抑制没有分隔符的行。除非指定本选项,否则,没有分隔符的行将原样传递。 .RE .SH 操作数 .sp .LP 支持下列操作数: .sp .ne 2 .mk .na \fB\fIfile\fR\fR .ad .RS 8n .rt 输入文件的路径名称。如果未指定 file 操作数或者 file 操作数为 \fB-\fR,则将使用标准输入。 .RE .SH 用法 .sp .LP 有关 \fBcut\fR 遇到大于或等于 2 GB(2^31 字节)文件时行为的说明,请参见 \fBlargefile\fR(5)。 .SH 示例 .LP \fB示例 1 \fR映射用户 ID .sp .LP 下面是从用户 \fBID\fR 到用户名的映射: .sp .in +2 .nf example% \fBcut -d: -f1,5 /etc/passwd\fR .fi .in -2 .sp .LP \fB示例 2 \fR设置当前登录名 .sp .LP 将 \fBname\fR 设置为当前登录名: .sp .in +2 .nf example$ \fBname=$(who am i | cut -f1 -d' ')\fR .fi .in -2 .sp .SH 环境变量 .sp .LP 有关影响 \fBcut\fR 执行的以下环境变量的说明,请参见 \fBenviron\fR(5):\fBLANG\fR、\fBLC_ALL\fR、\fBLC_CTYPE\fR、\fBLC_MESSAGES\fR 和 \fBNLSPATH\fR。 .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 \fBgrep\fR(1)、\fBpaste\fR(1)、\fBattributes\fR(5)、\fBenviron\fR(5)、\fBlargefile\fR(5)、\fBstandards\fR(5)