grep.texi

来自「linux平台中」· TEXI 代码 · 共 1,814 行 · 第 1/5 页

TEXI
1,814
字号
\input texinfo  @c -*-texinfo-*-@c %**start of header@setfilename grep.info@settitle grep, print lines matching a pattern@c %**end of header@c This file has the new style title page commands.@c Run `makeinfo' rather than `texinfo-format-buffer'.@c smallbook@c tex@c \overfullrule=0pt@c end tex@include version.texi@c Combine indices.@syncodeindex ky cp@syncodeindex pg cp@syncodeindex tp cp@defcodeindex op@syncodeindex op fn@syncodeindex vr fn@ifinfo@direntry* grep: (grep).                   print lines matching a pattern.@end direntryThis file documents @command{grep}, a pattern matching engine.Published by the Free Software Foundation,59 Temple Place - Suite 330Boston, MA 02111-1307, USA@c man begin COPYRIGHTCopyright @copyright{} 2000, 2001 Free Software Foundation, Inc.Permission is granted to make and distribute verbatim copies ofthis manual provided the copyright notice and this permission noticeare preserved on all copies.@ignorePermission is granted to process this file through TeX and print theresults, provided the printed document carries a copying permissionnotice identical to this one except for the removal of this paragraph(this paragraph not being relevant to the printed manual).@end ignorePermission is granted to copy, distribute and/or modify this documentunder the terms of the GNU Free Documentation License, Version 1.1 orany later version published by the Free Software Foundation; with theInvariant Sections being ``GNU General Public License'' and ``GNU FreeDocumentation License'', with no Front-Cover Texts, and with noBack-Cover Texts.  A copy of the license is included in the sectionentitled ``GNU Free Documentation License'' (@pxref{Copying}).@c man end@end ifinfo@setchapternewpage off@titlepage@title grep, searching for a pattern@subtitle version @value{VERSION}, @value{UPDATED}@author Alain Magloire et al.@page@vskip 0pt plus 1filllCopyright @copyright{} 2000, 2001 Free Software Foundation, Inc.@sp 2Published by the Free Software Foundation, @*59 Temple Place - Suite 330, @*Boston, MA 02111-1307, USAPermission is granted to copy, distribute and/or modify this documentunder the terms of the GNU Free Documentation License, Version 1.1 orany later version published by the Free Software Foundation; with theInvariant Sections being ``GNU General Public License'' and ``GNU FreeDocumentation License'', with no Front-Cover Texts, and with noBack-Cover Texts.  A copy of the license is included in the sectionentitled ``GNU Free Documentation License''.@end titlepage@ifnottex@node Top@top Grep@command{grep} searches for lines matching a pattern.This document was produced for version @value{VERSION} of @sc{gnu}@command{grep}.@end ifnottex@menu* Introduction::                Introduction.* Invoking::                    Invoking @command{grep}; description of options.* Diagnostics::                 Exit status returned by @command{grep}.* Grep Programs::               @command{grep} programs.* Regular Expressions::         Regular Expressions.* Usage::                       Examples.* Reporting Bugs::              Reporting Bugs.* Copying::                     License terms.* Concept Index::               A menu with all the topics in this manual.* Index::                       A menu with all @command{grep} commands                                 and command-line options.@end menu@node Introduction, Invoking, Top, Top@chapter Introduction@cindex Searching for a pattern.@command{grep} searches the input filesfor lines containing a match to a givenpattern list.  When it finds a match in a line, it copies the line to standardoutput (by default), or does whatever other sort of output you have requestedwith options.Though @command{grep} expects to do the matching on text,it has no limits on input line length other than available memory,and it can match arbitrary characters within a line.If the final byte of an input file is not a newline,@command{grep} silently supplies one.Since newline is also a separator for the list of patterns, thereis no way to match newline characters in a text.@node Invoking@chapter Invoking @command{grep}@command{grep} comes with a rich set of options from @sc{posix.2} and @sc{gnu}extensions.@table @samp@item -c@itemx --count@opindex -c@opindex --count@cindex counting linesSuppress normal output; instead print a count of matchinglines for each input file.  With the @samp{-v}, @samp{--invert-match} option,count non-matching lines.@item -e @var{pattern}@itemx --regexp=@var{pattern}@opindex -e@opindex --regexp=@var{pattern}@cindex pattern listUse @var{pattern} as the pattern; useful to protect patternsbeginning with a @samp{-}.@item -f @var{file}@itemx --file=@var{file}@opindex -f@opindex --file@cindex pattern from fileObtain patterns from @var{file}, one per line.  The emptyfile contains zero patterns, and therefore matches nothing.@item -i@itemx --ignore-case@opindex -i@opindex --ignore-case@cindex case insensitive searchIgnore case distinctions in both the pattern and the input files.@item -l@itemx --files-with-matches@opindex -l@opindex --files-with-matches@cindex names of matching filesSuppress normal output; instead print the name of each inputfile from which output would normally have been printed.The scanning of every file will stop on the first match.@item -n@itemx --line-number@opindex -n@opindex --line-number@cindex line numberingPrefix each line of output with the line number within its input file.@item -o@itemx --only-matching@opindex -o@opindex --only-matching@cindex only matchingPrint only the part of matching lines that actually matches @var{pattern}.@item -q@itemx --quiet@itemx --silent@opindex -q@opindex --quiet@opindex --silent@cindex quiet, silentQuiet; do not write anything to standard output.  Exit immediately withzero status if any match is found, even if an error was detected.  Alsosee the @samp{-s} or @samp{--no-messages} option.@item -s@itemx --no-messages@opindex -s@opindex --no-messages@cindex suppress error messagesSuppress error messages about nonexistent or unreadable files.Portability note: unlike @sc{gnu} @command{grep}, traditional@command{grep} did not conform to @sc{posix.2}, because traditional@command{grep} lacked a @samp{-q} option and its @samp{-s} option behavedlike @sc{gnu} @command{grep}'s @samp{-q} option.  Shell scripts intendedto be portable to traditional @command{grep} should avoid both@samp{-q} and @samp{-s} and should redirectoutput to @file{/dev/null} instead.@item -v@itemx --invert-match@opindex -v@opindex --invert-match@cindex invert matching@cindex print non-matching linesInvert the sense of matching, to select non-matching lines.@item -x@itemx --line-regexp@opindex -x@opindex --line-regexp@cindex match the whole lineSelect only those matches that exactly match the whole line.@end table@section @sc{gnu} Extensions@table @samp@item -A @var{num}@itemx --after-context=@var{num}@opindex -A@opindex --after-context@cindex after context@cindex context lines, after matchPrint @var{num} lines of trailing context after matching lines.@item -B @var{num}@itemx --before-context=@var{num}@opindex -B@opindex --before-context@cindex before context@cindex context lines, before matchPrint @var{num} lines of leading context before matching lines.@item -C @var{num}@itemx --context=@var{num}@opindex -C@opindex --context@cindex contextPrint @var{num} lines of output context.@item --colour[=@var{WHEN}]@itemx --color[=@var{WHEN}]@opindex --colour@cindex highlight, color, colourThe matching string is surrounded by the marker specify in @var{GREP_COLOR}.@var{WHEN} may be `never', `always', or `auto'.@item -@var{num}@opindex -NUMSame as @samp{--context=@var{num}} lines of leading and trailingcontext.  However, grep will never print any given line more than once.@item -V@itemx --version@opindex -V@opindex --version@cindex Version, printingPrint the version number of @command{grep} to the standard output stream.This version number should be included in all bug reports.@item --help@opindex --help@cindex Usage summary, printingPrint a usage message briefly summarizing these command-line optionsand the bug-reporting address, then exit.@itemx --binary-files=@var{type}@opindex --binary-files@cindex binary filesIf the first few bytes of a file indicate that the file contains binarydata, assume that the file is of type @var{type}.  By default,@var{type} is @samp{binary}, and @command{grep} normally outputs eithera one-line message saying that a binary file matches, or no message ifthere is no match.  If @var{type} is @samp{without-match},@command{grep} assumes that a binary file does not match;this is equivalent to the @samp{-I} option.  If @var{type}is @samp{text}, @command{grep} processes a binary file as if it weretext; this is equivalent to the @samp{-a} option.@emph{Warning:} @samp{--binary-files=text} might output binary garbage,which can have nasty side effects if the output is a terminal and if theterminal driver interprets some of it as commands.@item -b@itemx --byte-offset@opindex -b@opindex --byte-offset@cindex byte offsetPrint the byte offset within the input file before each line of output.When @command{grep} runs on @sc{ms-dos} or MS-Windows, the printedbyte offsetsdepend on whether the @samp{-u} (@samp{--unix-byte-offsets}) option isused; see below.@item -D @var{action}@itemx --devices=@var{action}@opindex -D@opindex --devices@cindex device searchIf an input file is a device, FIFO or socket, use @var{action} to process it.By default, @var{action} is @samp{read}, which means that devices areread just as if they were ordinary files.If @var{action} is @samp{skip}, devices, FIFOs and sockets are silentlyskipped.@item -d @var{action}@itemx --directories=@var{action}@opindex -d@opindex --directories@cindex directory searchIf an input file is a directory, use @var{action} to process it.By default, @var{action} is @samp{read}, which means that directories areread just as if they were ordinary files (some operating systemsand filesystems disallow this, and will cause @command{grep} to print errormessages for every directory or silently skip them). If @var{action} is@samp{skip}, directories are silently skipped.  If @var{action} is@samp{recurse}, @command{grep} reads all files under each directory,recursively; this is equivalent to the @samp{-r} option.@item -H@itemx --with-filename@opindex -H@opindex --With-filename@cindex with filename prefixPrint the filename for each match.@item -h@itemx --no-filename@opindex -h@opindex --no-filename@cindex no filename prefixSuppress the prefixing of filenames on output when multiple files are searched.@item --line-buffered@opindex --line-buffered@cindex line bufferingSet the line buffering policy, this can be a performance penality.@item --label=@var{LABEL}@opindex --label

⌨️ 快捷键说明

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