[wplug] escaping in sed

Bob Schmertz rschmertz at speakeasy.net
Wed Apr 30 12:24:34 EDT 2003


I'm not sure you've got exactly the right part of the info page, but 
what you're trying to say, I guess, is that Russ can pick another 
character, such as comma, instead of the slash, so the substitution 
expression would look like

s,NEEDLE,NEWNEEDLE,

To make this work, just use it.  Sed recognizes the first character 
after the 's' as the delimiter character to be used throughout the 
expression.

But using backslashes for the escape should work ('s/GNU\/Linux/Linux/' 
-- sorry, I couldn't think of anything else >:-)), as long as everything 
is also in single quotes to protect it from the shell.

On Wed, 30 Apr 2003, William Powell wrote:

>from the info page for sed:
>
>`\%REGEXP%'
>     (The `%' may be replaced by any other single character.)
>
>     This also matches the regular expression REGEXP, but allows one to
>     use a different delimiter than `/'.  This is particularly useful
>     if the REGEXP itself contains a lot of `/'s, since it avoids the
>     tedious escaping of every `/'.  If REGEXP itself includes any
>     delimiter characters, each must be escaped by a backslash (`\').
>
>
>Russ Schneider wrote:
>
>> If I'm using sed for
>>
>> sed s/NEEDLE/NEWNEEDLE/
>>
>> and NEWNEEDLE is http://www.sugapablo.com/
>>
>> How do I escape the /'s?
>>
>
>

-- 
Cheers,
Bob Schmertz





More information about the wplug mailing list