'\" te .\" Copyright 1989 AT&T .\" Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved .\" 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 egrep 1 "2006 年 3 月 24 日" "SunOS 5.11" "用户命令" .SH 名称 egrep \- 使用完整的正则表达式在文件中搜索某种模式 .SH 用法概要 .LP .nf \fB/usr/bin/egrep\fR [\fB-bchilnsv\fR] \fB-e\fR \fIpattern_list\fR [\fIfile...\fR] .fi .LP .nf \fB/usr/bin/egrep\fR [\fB-bchilnsv\fR] \fB-f\fR \fIfile\fR [\fIfile...\fR] .fi .LP .nf \fB/usr/bin/egrep\fR [\fB-bchilnsv\fR] \fIpattern\fR [\fIfile...\fR] .fi .LP .nf \fB/usr/xpg4/bin/egrep\fR [\fB-bchilnqsvx\fR] \fB-e\fR \fIpattern_list\fR [\fB-f\fR \fIfile\fR] [\fIfile...\fR] .fi .LP .nf \fB/usr/xpg4/bin/egrep\fR [\fB-bchilnqsvx\fR] [\fB-e\fR \fIpattern_list\fR] \fB-f\fR \fIfile\fR [\fIfile...\fR] .fi .LP .nf \fB/usr/xpg4/bin/egrep\fR [\fB-bchilnqsvx\fR] \fIpattern\fR [\fIfile...\fR] .fi .SH 描述 .sp .LP \fBegrep\fR (\fIexpression grep\fR) 实用程序在文件中搜索字符模式,并列显包含该模式的所有行。\fBegrep\fR 使用完整的正则表达式(此类表达式所含的字符串值使用字母数字和特殊字符的完整集合)来匹配模式。它使用快速的确定性算法,该算法有时需要指数空间。 .sp .LP 如果未指定任何文件,\fBegrep\fR 将采用标准输入。通常,所找到的每行均会被复制到标准输出。如果有多个输入文件,则会在所找到的每行前面列显文件名。 .SS "/usr/bin/egrep" .sp .LP \fB/usr/bin/egrep\fR 实用程序接受 \fBregexp\fR(5) 手册页中所述的完整正则表达式,但 \fB\(\fR 和 \fB\)\fR、\fB\(\fR 和 \fB\)\fR、\fB\{\fR 和 \fB\}\fR、\fB\<\fR 和 \fB\>\fR 以及 \fB\n\fR 除外,外加以下完整正则表达式,这些表达式也除外: .RS +4 .TP 1. 后跟 \fB+\fR 的完整正则表达式(匹配完整正则表达式的一次或多次出现)。 .RE .RS +4 .TP 2. 后跟 \fB?\fR 的完整正则表达式(匹配完整正则表达式的 0 次或 1 次出现)。 .RE .RS +4 .TP 3. 由 | 或\fB换行符\fR分隔的完整正则表达式(匹配由任意表达式匹配的字符串)。 .RE .RS +4 .TP 4. 可以由括号括起\fB()\fR以进行分组的完整正则表达式。 .RE .sp .LP 在\fI完整正则表达式\fR中使用字符 \fB$\fR、\fB*\fR、\fB[\fR、\fB^\fR、|、\fB(\fR、\fB)\fR 和 \fB\\fR 时要小心,因为这些字符对于 shell 也有意义。最安全的方法是,将整个\fI完整正则表达式\fR用单引号 (\fB´\fR\fB´\fR) 括起来。 .sp .LP 运算符的优先顺序依次是 \fB[ ]\fR、\fB* ? +\fR、串联、| 和换行符。 .SS "/usr/xpg4/bin/egrep" .sp .LP \fB/usr/xpg4/bin/egrep\fR 实用程序使用 \fBregex\fR(5) 手册页的 \fBEXTENDED REGULAR EXPRESSIONS\fR(扩展正则表达式)一节中介绍的正则表达式。 .SH 选项 .sp .LP \fB/usr/bin/egrep\fR 和 \fB/usr/xpg4/bin/egrep\fR 均支持以下选项: .sp .ne 2 .mk .na \fB\fB-b\fR\fR .ad .RS 19n .rt 在找到块的每行前面加上块编号。这在通过上下文定位块编号时可能很有用(第一个块是 0)。 .RE .sp .ne 2 .mk .na \fB\fB-c\fR\fR .ad .RS 19n .rt 只列显包含模式的行的计数。 .RE .sp .ne 2 .mk .na \fB\fB-e\fR \fIpattern_list\fR\fR .ad .RS 19n .rt 搜索 \fIpattern_list\fR(以 \fB-\fR 开头的\fI完整正则表达式\fR)。 .RE .sp .ne 2 .mk .na \fB\fB-f\fR \fIfile\fR\fR .ad .RS 19n .rt 从 \fIfile\fR 获取\fI完整\fR\fI正则\fR\fI表达式\fR的列表。 .RE .sp .ne 2 .mk .na \fB\fB-h\fR\fR .ad .RS 19n .rt 搜索多个文件时禁止列显文件名。 .RE .sp .ne 2 .mk .na \fB\fB-i\fR\fR .ad .RS 19n .rt 比较期间忽略大/小写区别。 .RE .sp .ne 2 .mk .na \fB\fB-l\fR\fR .ad .RS 19n .rt 列显一次具有匹配行的文件名(以换行符分隔)。多次找到模式时不重复文件的名称。 .RE .sp .ne 2 .mk .na \fB\fB-n\fR\fR .ad .RS 19n .rt 在文件中的每行前面加上其行号(第一行是 1)。 .RE .sp .ne 2 .mk .na \fB\fB-s\fR\fR .ad .RS 19n .rt 执行时无提示,即,除错误消息外不显示任何内容。这对于检查错误状态很有用。 .RE .sp .ne 2 .mk .na \fB\fB-v\fR\fR .ad .RS 19n .rt 列显包含模式的行以外的所有行。 .RE .SS "/usr/xpg4/bin/egrep" .sp .LP \fB/usr/xpg4/bin/egrep\fR 仅支持以下选项: .sp .ne 2 .mk .na \fB\fB-q\fR\fR .ad .RS 6n .rt 静默。不向标准输出写入任何内容(不考虑匹配行)。如果选择输入行,则以零状态退出。 .RE .sp .ne 2 .mk .na \fB\fB-x\fR\fR .ad .RS 6n .rt 只考虑这样的输入行:在行中使用所有字符以匹配要成为匹配行的整个固定字符串或正则表达式。 .RE .SH 操作数 .sp .LP 支持下列操作数: .sp .ne 2 .mk .na \fB\fIfile\fR\fR .ad .RS 8n .rt 要在其中搜索模式的文件的路径名。如果未指定 \fIfile\fR 操作数,将使用标准输入。 .RE .SS "/usr/bin/egrep" .sp .ne 2 .mk .na \fB\fIpattern\fR\fR .ad .RS 11n .rt 指定要在搜索输入内容期间使用的模式。 .RE .SS "/usr/xpg4/bin/egrep" .sp .ne 2 .mk .na \fB\fIpattern\fR\fR .ad .RS 11n .rt 指定要在搜索输入内容期间使用的一个或多个模式。此操作数被视为如同指定为 \fB-e\fR\fIpattern_list\fR。 .RE .SH 用法 .sp .LP 有关 \fBegrep\fR 遇到大于或等于 2 GB(2^31 字节)文件时行为的说明,请参见 \fBlargefile\fR(5)。 .SH 环境变量 .sp .LP 有关影响 \fBegrep\fR 执行的以下环境变量的说明,请参见 \fBenviron\fR(5):\fBLC_COLLATE\fR、\fB LC_CTYPE\fR、\fBLC_MESSAGES\fR 和 \fBNLSPATH\fR。 .SH 退出状态 .sp .LP 将返回以下退出值: .sp .ne 2 .mk .na \fB\fB0\fR\fR .ad .RS 5n .rt 如果找到任何匹配项。 .RE .sp .ne 2 .mk .na \fB\fB1\fR\fR .ad .RS 5n .rt 如果找不到任何匹配项。 .RE .sp .ne 2 .mk .na \fB\fB2\fR\fR .ad .RS 5n .rt 对于语法错误或不能访问的文件(即使找到匹配项)。 .RE .SH 属性 .sp .LP 有关下列属性的说明,请参见 \fBattributes\fR(5): .SS "/usr/bin/egrep" .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . 属性类型属性值 _ 可用性system/core-os _ CSINot Enabled(未启用) .TE .SS "/usr/xpg4/bin/egrep" .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . 属性类型属性值 _ 可用性system/xopen/xcu4 _ CSIEnabled(已启用) .TE .SH 另请参见 .sp .LP \fBfgrep\fR(1)、\fBgrep\fR(1)、\fBsed\fR(1)、\fBsh\fR(1)、\fBattributes\fR(5)、\fBenviron\fR(5)、\fBlargefile\fR(5)、\fBregex\fR(5)、\fBregexp\fR(5)、\fBXPG4\fR(5) .SH 附注 .sp .LP 理想情况下,应该只有一个 \fBgrep\fR 命令,但目前没有一种算法可以足够广泛地涵盖各种空间和时间权衡的情况。 .sp .LP 行仅受可用虚拟内存大小的限制。 .SS "/usr/xpg4/bin/egrep" .sp .LP \fB/usr/xpg4/bin/egrep\fR 实用程序与 \fB/usr/xpg4/bin/grep\fR \fB-E\fR 相同。请参见 \fBgrep\fR(1)。可移植应用程序应当使用 \fB/usr/xpg4/bin/grep\fR \fB-E\fR。