[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Changes to grep/manual/html_node/Usage.html,v
From: |
Jim Meyering |
Subject: |
Changes to grep/manual/html_node/Usage.html,v |
Date: |
Tue, 21 Sep 2010 06:07:10 +0000 |
CVSROOT: /webcvs/grep
Module name: grep
Changes by: Jim Meyering <meyering> 10/09/21 06:07:07
Index: html_node/Usage.html
===================================================================
RCS file: /webcvs/grep/grep/manual/html_node/Usage.html,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- html_node/Usage.html 2 Apr 2010 10:26:54 -0000 1.5
+++ html_node/Usage.html 21 Sep 2010 06:07:07 -0000 1.6
@@ -1,8 +1,8 @@
<html lang="en">
<head>
-<title>Usage - GNU Grep 2.6.3</title>
+<title>Usage - GNU Grep 2.7</title>
<meta http-equiv="Content-Type" content="text/html">
-<meta name="description" content="GNU Grep 2.6.3">
+<meta name="description" content="GNU Grep 2.7">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="prev" href="Regular-Expressions.html#Regular-Expressions"
title="Regular Expressions">
@@ -213,7 +213,29 @@
as there is no ‘<samp><span class="samp">aa</span></samp>’ in the
input, so the ‘<samp><span class="samp">\1</span></samp>’ in the
second alternate
has nothing to refer back to, meaning it will never match anything.
(The second alternate in this example can only match
-if the first alternate has matched – making the second one superfluous.)
+if the first alternate has matched—making the second one superfluous.)
+
+ <li>How can I match across lines?
+
+ <p>Standard grep cannot do this, as it is fundamentally line-based.
+Therefore, merely using the <code>[:space:]</code> character class does not
+match newlines in the way you might expect. However, if your grep is
+compiled with Perl patterns enabled, the Perl ‘<samp><span
class="samp">s</span></samp>’
+modifier (which makes <code>.</code> match newlines) can be used:
+
+ <pre class="example"> printf 'foo\nbar\n' | grep -P
'(?s)foo.*?bar'
+</pre>
+ <p>With the GNU <samp><span class="command">grep</span></samp> option
<code>-z</code> (see <a
href="File-and-Directory-Selection.html#File-and-Directory-Selection">File and
Directory Selection</a>), the input is terminated by null bytes. Thus,
+you can match newlines in the input, but the output will be the whole
+file, so this is really only useful to determine if the pattern is
+present:
+
+ <pre class="example"> printf 'foo\nbar\n' | grep -z -q
'foo[[:space:]]\+bar'
+</pre>
+ <p>Failing either of those options, you need to transform the input
+before giving it to <samp><span class="command">grep</span></samp>, or turn to
<samp><span class="command">awk</span></samp>,
+<samp><span class="command">sed</span></samp>, <samp><span
class="command">perl</span></samp>, or many other utilities that are
+designed to operate across lines.
<li>What do <samp><span class="command">grep</span></samp>, <samp><span
class="command">fgrep</span></samp>, and <samp><span
class="command">egrep</span></samp> stand for?
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Changes to grep/manual/html_node/Usage.html,v,
Jim Meyering <=