Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 159098 - 's' command doesn't work with '|' delimiter and '\|' in expression
Summary: 's' command doesn't work with '|' delimiter and '\|' in expression
Alias: None
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: sed
Version: 4.0
Hardware: All
OS: Linux
Target Milestone: ---
: ---
Assignee: Jakub Jelinek
QA Contact: Ben Levenson
Depends On:
TreeView+ depends on / blocked
Reported: 2005-05-29 16:05 UTC by Trevin Beattie
Modified: 2007-11-30 22:07 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2005-05-30 10:19:11 UTC
Target Upstream Version:

Attachments (Terms of Use)

Description Trevin Beattie 2005-05-29 16:05:20 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050516 Firefox/1.0.4

Description of problem:
I'm not sure whether this is a bug in sed or if it just isn't documented well; the info page for "The `s' Command" simply says: "The `/' characters may be uniformly replaced by any other single character within any given `s' command."

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
Run the following command on a machine with an smp or hugemem kernel loaded:

uname -r | sed 's|smp\|enterprise\|bigmem\|hugemem||g'

Actual Results:  2.4.21-27.5smp

Expected Results:  2.4.21-27.5

Additional info:

The correct result is output by changing the delimiter to another character, such as:

uname -r | sed 's_smp\|enterprise\|bigmem\|hugemem__g'

Sed also works as expected if the alternatives are removed from the expression, as in:

uname -r | sed 's|smp||g'

If '(' or ')' is used both in the expression and as a delimiter, the expression works, provided the character used as a delimiter is escaped in the expression, which means the metacharacter forms can't be used.  (Not that I would ever do that in real code, as it looks very confusing.)  If '.', '*', '[', or ']' is used both in the expression and as a delimiter, the expression works, provided the same metacharacter in the expression is escaped, which means they can't be used as literals (in which case you wouldn't want to use them as delimiters anyway).

Comment 1 Jakub Jelinek 2005-05-30 10:19:11 UTC
The sed behaviour is right.
When you use | as the delimiter character, | in the BRE must be escaped.
Therefore, \| in BRE is literal | character and there is no way how to express
\| (BRE alternation).  With sed -r (where EREs are used instead of BREs),
if | is used as delimiter character, \| in the ERE is ERE alternation and
there is no way to express literal character | in the ERE.
Perhaps man 1p sed
is more descriptive about this, it says:
Any backslash used to alter the default meaning of a subsequent character shall
be discarded from the BRE or the replacement before evaluating the BRE or using
the replacement.

Note You need to log in before you can comment on or make changes to this bug.