Print this page
3546 add support for grep -o option
   1 '\" te

   2 .\" Copyright 2012 Nexenta Systems, Inc. All rights reserved.
   3 .\" Copyright 1989 AT&T
   4 .\" Copyright (c) 2008, Sun Microsystems, Inc.  All Rights Reserved
   5 .\" Portions Copyright (c) 1992, X/Open Company Limited  All Rights Reserved
   6 .\" 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
   7 .\" http://www.opengroup.org/bookstore/.
   8 .\" 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.
   9 .\"  This notice shall appear on any product containing this material.
  10 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
  11 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
  12 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
  13 .TH GREP 1 "May 3, 2013"
  14 .SH NAME
  15 grep \- search a file for a pattern
  16 .SH SYNOPSIS
  17 .LP
  18 .nf
  19 \fB/usr/bin/grep\fR [\fB-c\fR | \fB-l\fR |\fB-q\fR] [\fB-r\fR | \fB-R\fR] [\fB-bHhinsvw\fR]
  20     \fIlimited-regular-expression\fR [\fIfilename\fR]...
  21 .fi
  22 
  23 .LP
  24 .nf
  25 \fB/usr/xpg4/bin/grep\fR [\fB-E\fR | \fB-F\fR] [\fB-c\fR | \fB-l\fR | \fB-q\fR] [\fB-r\fR | \fB-R\fR]
  26     [\fB-bHhinsvwx\fR] \fB-e\fR \fIpattern_list\fR... [\fB-f\fR \fIpattern_file\fR]...
  27     [\fIfile\fR]...
  28 .fi
  29 
  30 .LP
  31 .nf
  32 \fB/usr/xpg4/bin/grep\fR [\fB-E\fR | \fB-F\fR] [\fB-c\fR | \fB-l\fR | \fB-q\fR] [\fB-r\fR | \fB-R\fR]
  33     [\fB-bHhinsvwx\fR] [\fB-e\fR \fIpattern_list\fR]... \fB-f\fR \fIpattern_file\fR...
  34     [\fIfile\fR]...
  35 .fi
  36 
  37 .LP
  38 .nf
  39 \fB/usr/xpg4/bin/grep\fR [\fB-E\fR | \fB-F\fR] [\fB-c\fR | \fB-l\fR | \fB-q\fR] [\fB-r\fR | \fB-R\fR]
  40     [\fB-bHhinsvwx\fR] \fIpattern\fR [\fIfile\fR]...
  41 .fi
  42 
  43 .SH DESCRIPTION
  44 .sp
  45 .LP
  46 The \fBgrep\fR utility searches text files for a pattern and prints all lines
  47 that contain that pattern.  It uses a compact non-deterministic algorithm.
  48 .sp
  49 .LP
  50 Be careful using the characters \fB$\fR, \fB*\fR, \fB[\fR, \fB^\fR, \fB|\fR,
  51 \fB(\fR, \fB)\fR, and \fB\e\fR in the \fIpattern_list\fR because they are also
  52 meaningful to the shell. It is safest to enclose the entire \fIpattern_list\fR
  53 in single quotes \fBa\'\fR\&...\fBa\'\fR\&.
  54 .sp
  55 .LP
  56 If no files are specified, \fBgrep\fR assumes standard input. Normally, each
  57 line found is copied to standard output. The file name is printed before each
  58 line found if there is more than one input file.
  59 .SS "/usr/bin/grep"


 129 \fB\fB-l\fR\fR
 130 .ad
 131 .RS 6n
 132 Prints only the names of files with matching lines, separated by NEWLINE
 133 characters.  Does not repeat the names of files when the pattern is found more
 134 than once.
 135 .RE
 136 
 137 .sp
 138 .ne 2
 139 .na
 140 \fB\fB-n\fR\fR
 141 .ad
 142 .RS 6n
 143 Precedes each line by its line number in the file (first line is 1).
 144 .RE
 145 
 146 .sp
 147 .ne 2
 148 .na









 149 \fB\fB-r\fR\fR
 150 .ad
 151 .RS 6n
 152 Read all files under each directory, recursively. Follow symbolic links on
 153 the command line, but skip symlinks that are encountered recursively. If file
 154 is a device, FIFO, or socket, skip it.
 155 .RE
 156 
 157 .sp
 158 .ne 2
 159 .na
 160 \fB\fB-R\fR\fR
 161 .ad
 162 .RS 6n
 163 Read all files under each directory, recursively, following all symbolic links.
 164 .RE
 165 
 166 .sp
 167 .ne 2
 168 .na


   1 '\" te
   2 .\" Copyright (c) 2013 Andrew Stormont.  All rights reserved.
   3 .\" Copyright 2012 Nexenta Systems, Inc. All rights reserved.
   4 .\" Copyright 1989 AT&T
   5 .\" Copyright (c) 2008, Sun Microsystems, Inc.  All Rights Reserved
   6 .\" Portions Copyright (c) 1992, X/Open Company Limited  All Rights Reserved
   7 .\" 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
   8 .\" http://www.opengroup.org/bookstore/.
   9 .\" 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.
  10 .\"  This notice shall appear on any product containing this material.
  11 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
  12 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
  13 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
  14 .TH GREP 1 "May 3, 2013"
  15 .SH NAME
  16 grep \- search a file for a pattern
  17 .SH SYNOPSIS
  18 .LP
  19 .nf
  20 \fB/usr/bin/grep\fR [\fB-c\fR | \fB-l\fR | \fB-q\fR | \fB-o\fR] [\fB-r\fR | \fB-R\fR] [\fB-bHhinsvw\fR]
  21     \fIlimited-regular-expression\fR [\fIfilename\fR]...
  22 .fi
  23 
  24 .LP
  25 .nf
  26 \fB/usr/xpg4/bin/grep\fR [\fB-E\fR | \fB-F\fR] [\fB-c\fR | \fB-l\fR | \fB-q\fR | \fB-o\fR] [\fB-r\fR | \fB-R\fR]
  27     [\fB-bHhinsvwx\fR] \fB-e\fR \fIpattern_list\fR... [\fB-f\fR \fIpattern_file\fR]...
  28     [\fIfile\fR]...
  29 .fi
  30 
  31 .LP
  32 .nf
  33 \fB/usr/xpg4/bin/grep\fR [\fB-E\fR | \fB-F\fR] [\fB-c\fR | \fB-l\fR | \fB-q\fR | \fB-o\fR] [\fB-r\fR | \fB-R\fR]
  34     [\fB-bHhinsvwx\fR] [\fB-e\fR \fIpattern_list\fR]... \fB-f\fR \fIpattern_file\fR...
  35     [\fIfile\fR]...
  36 .fi
  37 
  38 .LP
  39 .nf
  40 \fB/usr/xpg4/bin/grep\fR [\fB-E\fR | \fB-F\fR] [\fB-c\fR | \fB-l\fR | \fB-q\fR | \fB-o\fR] [\fB-r\fR | \fB-R\fR]
  41     [\fB-bHhinsvwx\fR] \fIpattern\fR [\fIfile\fR]...
  42 .fi
  43 
  44 .SH DESCRIPTION
  45 .sp
  46 .LP
  47 The \fBgrep\fR utility searches text files for a pattern and prints all lines
  48 that contain that pattern.  It uses a compact non-deterministic algorithm.
  49 .sp
  50 .LP
  51 Be careful using the characters \fB$\fR, \fB*\fR, \fB[\fR, \fB^\fR, \fB|\fR,
  52 \fB(\fR, \fB)\fR, and \fB\e\fR in the \fIpattern_list\fR because they are also
  53 meaningful to the shell. It is safest to enclose the entire \fIpattern_list\fR
  54 in single quotes \fBa\'\fR\&...\fBa\'\fR\&.
  55 .sp
  56 .LP
  57 If no files are specified, \fBgrep\fR assumes standard input. Normally, each
  58 line found is copied to standard output. The file name is printed before each
  59 line found if there is more than one input file.
  60 .SS "/usr/bin/grep"


 130 \fB\fB-l\fR\fR
 131 .ad
 132 .RS 6n
 133 Prints only the names of files with matching lines, separated by NEWLINE
 134 characters.  Does not repeat the names of files when the pattern is found more
 135 than once.
 136 .RE
 137 
 138 .sp
 139 .ne 2
 140 .na
 141 \fB\fB-n\fR\fR
 142 .ad
 143 .RS 6n
 144 Precedes each line by its line number in the file (first line is 1).
 145 .RE
 146 
 147 .sp
 148 .ne 2
 149 .na
 150 \fB\fB-o\fR\fR
 151 .ad
 152 .RS 6n
 153 Print only the matching part of the line.
 154 .RE
 155 
 156 .sp
 157 .ne 2
 158 .na
 159 \fB\fB-r\fR\fR
 160 .ad
 161 .RS 6n
 162 Read all files under each directory, recursively. Follow symbolic links on
 163 the command line, but skip symlinks that are encountered recursively. If file
 164 is a device, FIFO, or socket, skip it.
 165 .RE
 166 
 167 .sp
 168 .ne 2
 169 .na
 170 \fB\fB-R\fR\fR
 171 .ad
 172 .RS 6n
 173 Read all files under each directory, recursively, following all symbolic links.
 174 .RE
 175 
 176 .sp
 177 .ne 2
 178 .na