grep.1

来自「早期freebsd实现」· 1 代码 · 共 251 行

1
251
字号
.\" Copyright (c) 1980, 1990, 1993.\"	The Regents of the University of California.  All rights reserved..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\"    notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\"    notice, this list of conditions and the following disclaimer in the.\"    documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\"    must display the following acknowledgement:.\"	This product includes software developed by the University of.\"	California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\"    may be used to endorse or promote products derived from this software.\"    without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\"	@(#)grep.1	8.3 (Berkeley) 4/18/94.\".Dd April 18, 1994.Dt GREP 1.Os.Sh NAME.Nm grep.Nd file pattern searcher.Sh SYNOPSIS.Nm grep.Op Fl bchilnosvw.Op Fl e Ar pattern.Op Ar.Nm egrep.Op Fl bchilnosv.Op Fl e Ar pattern.Op Fl f Ar pattern_file.Op Ar.Nm fgrep.Op Fl bchilnosvx.Op Fl e Ar pattern.Op Fl f Ar pattern_file.Op Ar.Sh DESCRIPTIONThe.Nm greputilities search the given input files selecting lineswhich match one or more patterns; the type of patterns is controlledby the options specified.By default, a patternmatches an input line if any regular expression (RE) in thepattern matches the input line without its trailing <new-line>.A null RE matches every line.Each input line that matches atleast one of the patterns is written to the standard output..PpFor simple patterns or.Xr ex 1or.Xr ed 1style regular expressions, the.Nm greputility is used.The.Nm egreputilitycan handle extended regular expressions andembedded <newline>s in patterns.The.Nm fgreputility is quick but can handle only fixed strings.A fixed stringis a string of characters,each characteris matched only by itself.The patternvalue can consist of multiple lines withembedded <newline>s.In this case, the <newline>sact as alternation characters, allowing any of thepattern lines to match a portion of the input..PpThe following options are available:.Pp.Bl -tag -width indent.It Fl bThe block number on the disk in which a matched pattern is locatedis displayed in front of the respective matched line..It Fl cOnly a count of selected lines is written to standardoutput..It Fl e Ar expression Specify a pattern used during the search of theinput.Multiple.Fl eoptions can be used to specifymultiple patterns; an input line is selected if itmatches any of the specified patterns..It Fl f Ar pattern_file The pattern is read from the file named by thepathname pattern_file.Trailing newlinesin the pattern_file are ignored..Pf ( Nm Egrepand.Nm fgreponly)..It Fl hNever print filename headers with output lines..It Fl iThe case of letters is ignored in making comparisons \- that is, upper andlower case are considered identical..It Fl lOnly the names of files containing selected linesare written to standard output.Pathnames arelisted once per file searched.If the standardinput is searched, the pathname.Sq Flis written..It Fl nEach output line is preceded by its relative linenumber in the file; each file starting at line 1.The line number counter is reset for each file processed.This option is ignored if.Fl c ,.Fl l ,or.Fl sisspecified..It Fl oAlways print filename headers with output lines..It Fl sSilent mode.  Nothing is printed (except error messages).This is useful for checking the error status..It Fl vSelected lines are those.Em notmatching the specifiedpatterns..It Fl xOnly input lines selected against an entire fixedstring or regular expression are considered to bematching lines..Pf ( Nm Fgreponly)..It Fl wThe expression is searched for as a word(as if surrounded by `\e<' and `\e>', see.Xr ex  1  . ).Pf ( Nm Greponly).Pp.ElIf no file arguments are specified, thestandard input is used..PpThe.Nm greputility exits with one of the following values:.Pp.Bl -tag -width flag -compact.It Li 0One or more lines were selected..It Li 1No lines were selected..It Li >1An error occurred..El.Sh EXTENDED REGULAR EXPRESSIONSThe following characters are interpreted by.Nm egrep :.Pp.Bl -tag -width flag -compact.It Cm \&$Align the match from the end of the line..It Cm \&^Align the match from the beginning of the line..It Cm \&|Add another pattern (see example below)..It Cm \&?Match 1 or less sequential repetitions of the pattern..It Cm \&+Match 1 or more sequential repetitions of the pattern..It Cm \&*Match 0 or more sequential repetitions of the pattern..It Cm \&[]Match any single character or range of charactersenclosed in the brackets..It Cm \&\eEscape special characters which have meaning to.Nm egrep ,the set of {$,.,^,[,],|,?,+,*,(,)}..El.Sh EXAMPLESTo find all occurrences of the word patricia in a file:.Pp.Dl grep patricia myfile.PpTo find all occurrences of the pattern.Ql \&.Ppat the beginning of a line:.Pp.Dl grep '^\e.Pp'.PpThe apostrophes assure the entire expression is evaluated by.Nm grepinstead of by theusers shell.The carat or hat.Ql Li \&^means.Em from the beginning of a line ,and the.Ql Li \&\eescapes the.Ql Li \&.which would otherwise match any character..PpA simple example of an extended regular expression:.Pp.Dl egrep '19|20|25' calendar.PpPeruses the file calendar looking for either 19, 20or 25..Sh SEE ALSO.Xr ed 1 ,.Xr ex 1 ,.Xr sed 1.Sh HISTORYThe.Nm grepcommand appeared in.At v6 ..Sh BUGSLines are limited to 256 characters; longer lines are truncated.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?