The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   UNIX - Newcomers (http://hintsforums.macworld.com/forumdisplay.php?f=15)
-   -   Piping ls and sed to mv (http://hintsforums.macworld.com/showthread.php?t=102528)

jbc 06-16-2009 09:55 AM

On my Tiger setup, \0 does *not* work with the default installed sed. However, it works fine with the MacPorts-installed gsed (GNU sed) without using ERE's. The gsed man page contains only this:
Code:

      s/regexp/replacement/
              Attempt  to match regexp against the pattern space.  If success-
              ful,  replace  that  portion  matched  with  replacement.    The
              replacement may contain the special character & to refer to that
              portion of the pattern space  which  matched,  and  the  special
              escapes  \1  through  \9  to refer to the corresponding matching
              sub-expressions in the regexp.

There's no mention of \0, although it seems to work. The gsed man page lists the version as 4.1.4, February 2006.

Hal Itosis 06-16-2009 07:02 PM

Quote:

Originally Posted by jbc (Post 538334)
On my Tiger setup, \0 does *not* work with the default installed sed. However, it works fine with the MacPorts-installed gsed (GNU sed) without using ERE's. The gsed man page contains only this:

s/regexp/replacement/

Attempt to match regexp against the pattern space. If successful, replace that portion matched with replacement. The replacement may contain the special character & to refer to that portion of the pattern space which matched, and the special escapes \1 through \9 to refer to the corresponding matching sub-expressions in the regexp.

There's no mention of \0, although it seems to work. The gsed man page lists the version as 4.1.4, February 2006.

And the ancient OSX sed says:
Quote:

[2addr]s/regular expression/replacement/flags

Substitute the replacement string for the first instance of the regular expression in the pattern space. Any character other than backslash or newline can be used instead of a slash to delimit the RE and the replacement. Within the RE and the replacement, the RE delimiter itself can be used as a literal character if it is preceded by a backslash.

An ampersand (``&'') appearing in the replacement is replaced by the string matching the RE. The special meaning of ``&'' in this context can be suppressed by preceding it by a backslash. The string ``\#'', where ``#'' is a digit, is replaced by the text matched by the corresponding backreference expression (see re_format(7)).

...so, & is mentioned in both man pages (as well as every tutorial i ever read, such as).

Where is \0 documented?

[as both man pages above go on to say, escaped numbers like \1 \2 \3 etc., are used for back references to portions captured within \( parens \). I can see where \0 is a cool notation for the whole RE... i just don't see where that convention was ever established.]


All times are GMT -5. The time now is 10:17 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.