From de6b6ccd7400b6483ecee5eebc7d48666b497680 Mon Sep 17 00:00:00 2001 From: Assaf Gordon Date: Fri, 24 Feb 2017 00:49:20 -0500 Subject: [PATCH] doc: elaborate about regex matching on pattern space Regex addresses work on current pattern space, not on the original input lines. From https://bugs.debian.org/284646 * doc/sed.texi (Regexp Addresses): Add a paragraph and an example. * doc/sed.x (Addresses): Add a sentence about regexp. --- doc/sed.texi | 27 +++++++++++++++++++++++++++ doc/sed.x | 2 ++ 2 files changed, 29 insertions(+) diff --git a/doc/sed.texi b/doc/sed.texi index a6846b0..6b272ee 100644 --- a/doc/sed.texi +++ b/doc/sed.texi @@ -2265,6 +2265,33 @@ the period character does not match a new-line character in multi-line mode. @end table + +@cindex regex addresses and pattern space +@cindex regex addresses and input lines +Regex addresses operate on the content of the current +pattern space. If the pattern space is changed (for example with @code{s///} +command) the regular expression matching will operate on the changed text. + +In the following example, automatic printing is disabled with +@option{-n}. The @code{s/2/X/} command changes lines containing +@samp{2} to @samp{X}. The command @code{/[0-9]/p} matches +lines with digits and prints them. +Because the second line is changed before the @code{/[0-9]/} regex, +it will not match and will not be printed: + +@codequoteundirected on +@codequotebacktick on +@example +@group +$ seq 3 | sed -n 's/2/X/ ; /[0-9]/p' +1 +3 +@end group +@end example +@codequoteundirected off +@codequotebacktick off + + @node Range Addresses @section Range Addresses diff --git a/doc/sed.x b/doc/sed.x index 401bd88..b2e0beb 100644 --- a/doc/sed.x +++ b/doc/sed.x @@ -257,6 +257,8 @@ Match the last line. .RI / regexp / Match lines matching the regular expression .IR regexp . +Matching is performed on the current pattern space, which +can be modified with commands such as ``s///''. .TP .BI \fR\e\fPc regexp c Match lines matching the regular expression