CVSROOT: /webcvs/grep Module name: grep Changes by: Jim Meyering <meyering> 16/02/05 00:44:53
Index: html_node/General-Output-Control.html =================================================================== RCS file: /webcvs/grep/grep/manual/html_node/General-Output-Control.html,v retrieving revision 1.21 retrieving revision 1.22 diff -u -b -r1.21 -r1.22 --- html_node/General-Output-Control.html 2 Nov 2015 02:54:34 -0000 1.21 +++ html_node/General-Output-Control.html 5 Feb 2016 00:44:52 -0000 1.22 @@ -1,149 +1,234 @@ -<html lang="en"> +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html> +<!-- This manual is for grep, a pattern matching engine. + +Copyright (C) 1999-2002, 2005, 2008-2016 Free Software Foundation, +Inc. + +Permission is granted to copy, distribute and/or modify this document +under the terms of the GNU Free Documentation License, Version 1.3 or +any later version published by the Free Software Foundation; with no +Invariant Sections, with no Front-Cover Texts, and with no Back-Cover +Texts. A copy of the license is included in the section entitled +"GNU Free Documentation License". --> +<!-- Created by GNU Texinfo 6.0, http://www.gnu.org/software/texinfo/ --> <head> -<title>General Output Control - GNU Grep 2.22</title> +<title>GNU Grep 2.23: General Output Control</title> + +<meta name="description" content="GNU Grep 2.23: General Output Control"> +<meta name="keywords" content="GNU Grep 2.23: General Output Control"> +<meta name="resource-type" content="document"> +<meta name="distribution" content="global"> +<meta name="Generator" content="makeinfo"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> -<meta name="description" content="GNU Grep 2.22"> -<meta name="generator" content="makeinfo 4.13"> -<link title="Top" rel="start" href="index.html#Top"> -<link rel="up" href="Command_002dline-Options.html#Command_002dline-Options" title="Command-line Options"> -<link rel="prev" href="Matching-Control.html#Matching-Control" title="Matching Control"> -<link rel="next" href="Output-Line-Prefix-Control.html#Output-Line-Prefix-Control" title="Output Line Prefix Control"> -<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> +<link href="index.html#Top" rel="start" title="Top"> +<link href="Index.html#Index" rel="index" title="Index"> +<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> +<link href="Command_002dline-Options.html#Command_002dline-Options" rel="up" title="Command-line Options"> +<link href="Output-Line-Prefix-Control.html#Output-Line-Prefix-Control" rel="next" title="Output Line Prefix Control"> +<link href="Matching-Control.html#Matching-Control" rel="prev" title="Matching Control"> +<style type="text/css"> <!-- -This manual is for `grep', a pattern matching engine. +a.summary-letter {text-decoration: none} +blockquote.indentedblock {margin-right: 0em} +blockquote.smallindentedblock {margin-right: 0em; font-size: smaller} +blockquote.smallquotation {font-size: smaller} +div.display {margin-left: 3.2em} +div.example {margin-left: 3.2em} +div.lisp {margin-left: 3.2em} +div.smalldisplay {margin-left: 3.2em} +div.smallexample {margin-left: 3.2em} +div.smalllisp {margin-left: 3.2em} +kbd {font-style: oblique} +pre.display {font-family: inherit} +pre.format {font-family: inherit} +pre.menu-comment {font-family: serif} +pre.menu-preformatted {font-family: serif} +pre.smalldisplay {font-family: inherit; font-size: smaller} +pre.smallexample {font-size: smaller} +pre.smallformat {font-family: inherit; font-size: smaller} +pre.smalllisp {font-size: smaller} +span.nocodebreak {white-space: nowrap} +span.nolinebreak {white-space: nowrap} +span.roman {font-family: serif; font-weight: normal} +span.sansserif {font-family: sans-serif; font-weight: normal} +ul.no-bullet {list-style: none} +--> +</style> +<link rel="stylesheet" type="text/css" href="/software/gnulib/manual.css"> -Copyright (C) 1999-2002, 2005, 2008-2015 Free Software Foundation, -Inc. - Permission is granted to copy, distribute and/or modify this - document under the terms of the GNU Free Documentation License, - Version 1.3 or any later version published by the Free Software - Foundation; with no Invariant Sections, with no Front-Cover Texts, - and with no Back-Cover Texts. A copy of the license is included - in the section entitled ``GNU Free Documentation License''. - --> -<meta http-equiv="Content-Style-Type" content="text/css"> -<style type="text/css"><!-- - pre.display { font-family:inherit } - pre.format { font-family:inherit } - pre.smalldisplay { font-family:inherit; font-size:smaller } - pre.smallformat { font-family:inherit; font-size:smaller } - pre.smallexample { font-size:smaller } - pre.smalllisp { font-size:smaller } - span.sc { font-variant:small-caps } - span.roman { font-family:serif; font-weight:normal; } - span.sansserif { font-family:sans-serif; font-weight:normal; } ---></style> -<link rel="stylesheet" type="text/css" href="/software/gnulib/manual.css"> </head> -<body> -<div class="node"> + +<body lang="en"> <a name="General-Output-Control"></a> +<div class="header"> <p> -Next: <a rel="next" accesskey="n" href="Output-Line-Prefix-Control.html#Output-Line-Prefix-Control">Output Line Prefix Control</a>, -Previous: <a rel="previous" accesskey="p" href="Matching-Control.html#Matching-Control">Matching Control</a>, -Up: <a rel="up" accesskey="u" href="Command_002dline-Options.html#Command_002dline-Options">Command-line Options</a> -<hr> +Next: <a href="Output-Line-Prefix-Control.html#Output-Line-Prefix-Control" accesskey="n" rel="next">Output Line Prefix Control</a>, Previous: <a href="Matching-Control.html#Matching-Control" accesskey="p" rel="prev">Matching Control</a>, Up: <a href="Command_002dline-Options.html#Command_002dline-Options" accesskey="u" rel="up">Command-line Options</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p> </div> - +<hr> +<a name="General-Output-Control-1"></a> <h4 class="subsection">2.1.3 General Output Control</h4> - <dl> -<dt><samp><span class="option">-c</span></samp><dt><samp><span class="option">--count</span></samp><dd><a name="index-g_t_002dc-27"></a><a name="index-g_t_002d_002dcount-28"></a><a name="index-counting-lines-29"></a>Suppress normal output; +<dl compact="compact"> +<dt><samp>-c</samp></dt> +<dt><samp>--count</samp></dt> +<dd><a name="index-_002dc"></a> +<a name="index-_002d_002dcount"></a> +<a name="index-counting-lines"></a> +<p>Suppress normal output; instead print a count of matching lines for each input file. -With the <samp><span class="option">-v</span></samp> (<samp><span class="option">--invert-match</span></samp>) option, +With the <samp>-v</samp> (<samp>--invert-match</samp>) option, count non-matching lines. -(<samp><span class="option">-c</span></samp> is specified by POSIX.) - - <br><dt><samp><span class="option">--color[=</span><var>WHEN</var><span class="option">]</span></samp><dt><samp><span class="option">--colour[=</span><var>WHEN</var><span class="option">]</span></samp><dd><a name="index-g_t_002d_002dcolor-30"></a><a name="index-g_t_002d_002dcolour-31"></a><a name="index-highlight_002c-color_002c-colour-32"></a>Surround the matched (non-empty) strings, matching lines, context lines, +(<samp>-c</samp> is specified by POSIX.) +</p> +</dd> +<dt><samp>--color[=<var>WHEN</var>]</samp></dt> +<dt><samp>--colour[=<var>WHEN</var>]</samp></dt> +<dd><a name="index-_002d_002dcolor"></a> +<a name="index-_002d_002dcolour"></a> +<a name="index-highlight_002c-color_002c-colour"></a> +<p>Surround the matched (non-empty) strings, matching lines, context lines, file names, line numbers, byte offsets, and separators (for fields and groups of context lines) with escape sequences to display them in color on the terminal. -The colors are defined by the environment variable <samp><span class="env">GREP_COLORS</span></samp> -and default to ‘<samp><span class="samp">ms=01;31:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36</span></samp>’ +The colors are defined by the environment variable <code>GREP_COLORS</code> +and default to ‘<samp>ms=01;31:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36</samp>’ for bold red matched text, magenta file names, green line numbers, green byte offsets, cyan separators, and default terminal colors otherwise. -The deprecated environment variable <samp><span class="env">GREP_COLOR</span></samp> is still supported, +The deprecated environment variable <code>GREP_COLOR</code> is still supported, but its setting does not have priority; -it defaults to ‘<samp><span class="samp">01;31</span></samp>’ (bold red) +it defaults to ‘<samp>01;31</samp>’ (bold red) which only covers the color for matched text. -<var>WHEN</var> is ‘<samp><span class="samp">never</span></samp>’, ‘<samp><span class="samp">always</span></samp>’, or ‘<samp><span class="samp">auto</span></samp>’. - - <br><dt><samp><span class="option">-L</span></samp><dt><samp><span class="option">--files-without-match</span></samp><dd><a name="index-g_t_002dL-33"></a><a name="index-g_t_002d_002dfiles_002dwithout_002dmatch-34"></a><a name="index-files-which-don_0027t-match-35"></a>Suppress normal output; +<var>WHEN</var> is ‘<samp>never</samp>’, ‘<samp>always</samp>’, or ‘<samp>auto</samp>’. +</p> +</dd> +<dt><samp>-L</samp></dt> +<dt><samp>--files-without-match</samp></dt> +<dd><a name="index-_002dL"></a> +<a name="index-_002d_002dfiles_002dwithout_002dmatch"></a> +<a name="index-files-which-don_0027t-match"></a> +<p>Suppress normal output; instead print the name of each input file from which no output would normally have been printed. The scanning of each file stops on the first match. - - <br><dt><samp><span class="option">-l</span></samp><dt><samp><span class="option">--files-with-matches</span></samp><dd><a name="index-g_t_002dl-36"></a><a name="index-g_t_002d_002dfiles_002dwith_002dmatches-37"></a><a name="index-names-of-matching-files-38"></a>Suppress normal output; +</p> +</dd> +<dt><samp>-l</samp></dt> +<dt><samp>--files-with-matches</samp></dt> +<dd><a name="index-_002dl"></a> +<a name="index-_002d_002dfiles_002dwith_002dmatches"></a> +<a name="index-names-of-matching-files"></a> +<p>Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning of each file stops on the first match. -(<samp><span class="option">-l</span></samp> is specified by POSIX.) - - <br><dt><samp><span class="option">-m </span><var>num</var></samp><dt><samp><span class="option">--max-count=</span><var>num</var></samp><dd><a name="index-g_t_002dm-39"></a><a name="index-g_t_002d_002dmax_002dcount-40"></a><a name="index-max_002dcount-41"></a>Stop reading a file after <var>num</var> matching lines. +(<samp>-l</samp> is specified by POSIX.) +</p> +</dd> +<dt><samp>-m <var>num</var></samp></dt> +<dt><samp>--max-count=<var>num</var></samp></dt> +<dd><a name="index-_002dm"></a> +<a name="index-_002d_002dmax_002dcount"></a> +<a name="index-max_002dcount"></a> +<p>Stop reading a file after <var>num</var> matching lines. If the input is standard input from a regular file, and <var>num</var> matching lines are output, -<samp><span class="command">grep</span></samp> ensures that the standard input is positioned +<code>grep</code> ensures that the standard input is positioned just after the last matching line before exiting, regardless of the presence of trailing context lines. This enables a calling process to resume a search. For example, the following shell script makes use of it: - - <pre class="example"> while grep -m 1 PATTERN - do +</p> +<div class="example"> +<pre class="example">while grep -m 1 PATTERN +do echo xxxx - done < FILE -</pre> - <p>But the following probably will not work because a pipe is not a regular -file: +done < FILE +</pre></div> - <pre class="example"> # This probably will not work. - cat FILE | - while grep -m 1 PATTERN - do +<p>But the following probably will not work because a pipe is not a regular +file: +</p> +<div class="example"> +<pre class="example"># This probably will not work. +cat FILE | +while grep -m 1 PATTERN +do echo xxxx - done -</pre> - <p>When <samp><span class="command">grep</span></samp> stops after <var>num</var> matching lines, +done +</pre></div> + +<p>When <code>grep</code> stops after <var>num</var> matching lines, it outputs any trailing context lines. Since context does not include matching lines, -<samp><span class="command">grep</span></samp> will stop when it encounters another matching line. -When the <samp><span class="option">-c</span></samp> or <samp><span class="option">--count</span></samp> option is also used, -<samp><span class="command">grep</span></samp> does not output a count greater than <var>num</var>. -When the <samp><span class="option">-v</span></samp> or <samp><span class="option">--invert-match</span></samp> option is also used, -<samp><span class="command">grep</span></samp> stops after outputting <var>num</var> non-matching lines. - - <br><dt><samp><span class="option">-o</span></samp><dt><samp><span class="option">--only-matching</span></samp><dd><a name="index-g_t_002do-42"></a><a name="index-g_t_002d_002donly_002dmatching-43"></a><a name="index-only-matching-44"></a>Print only the matched (non-empty) parts of matching lines, +<code>grep</code> will stop when it encounters another matching line. +When the <samp>-c</samp> or <samp>--count</samp> option is also used, +<code>grep</code> does not output a count greater than <var>num</var>. +When the <samp>-v</samp> or <samp>--invert-match</samp> option is also used, +<code>grep</code> stops after outputting <var>num</var> non-matching lines. +</p> +</dd> +<dt><samp>-o</samp></dt> +<dt><samp>--only-matching</samp></dt> +<dd><a name="index-_002do"></a> +<a name="index-_002d_002donly_002dmatching"></a> +<a name="index-only-matching"></a> +<p>Print only the matched (non-empty) parts of matching lines, with each such part on a separate output line. - - <br><dt><samp><span class="option">-q</span></samp><dt><samp><span class="option">--quiet</span></samp><dt><samp><span class="option">--silent</span></samp><dd><a name="index-g_t_002dq-45"></a><a name="index-g_t_002d_002dquiet-46"></a><a name="index-g_t_002d_002dsilent-47"></a><a name="index-quiet_002c-silent-48"></a>Quiet; do not write anything to standard output. +</p> +</dd> +<dt><samp>-q</samp></dt> +<dt><samp>--quiet</samp></dt> +<dt><samp>--silent</samp></dt> +<dd><a name="index-_002dq"></a> +<a name="index-_002d_002dquiet"></a> +<a name="index-_002d_002dsilent"></a> +<a name="index-quiet_002c-silent"></a> +<p>Quiet; do not write anything to standard output. Exit immediately with zero status if any match is found, even if an error was detected. -Also see the <samp><span class="option">-s</span></samp> or <samp><span class="option">--no-messages</span></samp> option. -(<samp><span class="option">-q</span></samp> is specified by POSIX.) - - <br><dt><samp><span class="option">-s</span></samp><dt><samp><span class="option">--no-messages</span></samp><dd><a name="index-g_t_002ds-49"></a><a name="index-g_t_002d_002dno_002dmessages-50"></a><a name="index-suppress-error-messages-51"></a>Suppress error messages about nonexistent or unreadable files. +Also see the <samp>-s</samp> or <samp>--no-messages</samp> option. +(<samp>-q</samp> is specified by POSIX.) +</p> +</dd> +<dt><samp>-s</samp></dt> +<dt><samp>--no-messages</samp></dt> +<dd><a name="index-_002ds"></a> +<a name="index-_002d_002dno_002dmessages"></a> +<a name="index-suppress-error-messages"></a> +<p>Suppress error messages about nonexistent or unreadable files. Portability note: -unlike GNU <samp><span class="command">grep</span></samp>, -7th Edition Unix <samp><span class="command">grep</span></samp> did not conform to POSIX, -because it lacked <samp><span class="option">-q</span></samp> -and its <samp><span class="option">-s</span></samp> option behaved like -GNU <samp><span class="command">grep</span></samp>'s <samp><span class="option">-q</span></samp> option.<a rel="footnote" href="#fn-1" name="fnd-1"><sup>1</sup></a> -USG-style <samp><span class="command">grep</span></samp> also lacked <samp><span class="option">-q</span></samp> -but its <samp><span class="option">-s</span></samp> option behaved like GNU <samp><span class="command">grep</span></samp>'s. +unlike GNU <code>grep</code>, +7th Edition Unix <code>grep</code> did not conform to POSIX, +because it lacked <samp>-q</samp> +and its <samp>-s</samp> option behaved like +GNU <code>grep</code>’s <samp>-q</samp> option.<a name="DOCF1" href="#FOOT1"><sup>1</sup></a> +USG-style <code>grep</code> also lacked <samp>-q</samp> +but its <samp>-s</samp> option behaved like GNU <code>grep</code>’s. Portable shell scripts should avoid both -<samp><span class="option">-q</span></samp> and <samp><span class="option">-s</span></samp> and should redirect -standard and error output to <samp><span class="file">/dev/null</span></samp> instead. -(<samp><span class="option">-s</span></samp> is specified by POSIX.) - +<samp>-q</samp> and <samp>-s</samp> and should redirect +standard and error output to <samp>/dev/null</samp> instead. +(<samp>-s</samp> is specified by POSIX.) +</p> +</dd> </dl> - <div class="footnote"> +<div class="footnote"> <hr> -<h4>Footnotes</h4><p class="footnote"><small>[<a name="fn-1" href="#fnd-1">1</a>]</small> Of course, 7th Edition +<h4 class="footnotes-heading">Footnotes</h4> + +<h3><a name="FOOT1" href="#DOCF1">(1)</a></h3> +<p>Of course, 7th Edition Unix predated POSIX by several years!</p> +</div> +<hr> +<div class="header"> +<p> +Next: <a href="Output-Line-Prefix-Control.html#Output-Line-Prefix-Control" accesskey="n" rel="next">Output Line Prefix Control</a>, Previous: <a href="Matching-Control.html#Matching-Control" accesskey="p" rel="prev">Matching Control</a>, Up: <a href="Command_002dline-Options.html#Command_002dline-Options" accesskey="u" rel="up">Command-line Options</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p> +</div> - <hr></div> - </body></html> +</body> +</html>
