Thanks, Cameron.  It's a cool idea, but I can't get the leading and trailing
spaces to stick within a variable.  The following script and it's output
will show you what I mean:

list="one two three four"
list=`echo $list | sed "s/^/ /"`
echo $list
list=`echo $list | sed "s/$/ /"`
echo $list
list=`echo $list | sed "s/ one / /"`
echo $list
list=`echo $list | sed "s/ four / /"`
echo $list
list=`echo $list | sed "s/^ //"`
echo $list
list=`echo $list | sed "s/ $//"`
echo $list

Output:
one two three four
one two three four
one two three four
one two three four
one two three four
one two three four

However, if I make list="x one two three four x", I get the desired results,
and I can remove the 'x ' and ' x' when done.

Is there a way to get leading and trailing spaces (and multiple spaces
between words) to stick in variables, or this a "feature" of bash?

bd

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Cameron Simpson
Sent: Friday, January 05, 2001 3:22 PM
To: [EMAIL PROTECTED]
Cc: Brad Doster
Subject: Re: Whole word substitution with sed


| On Wed, 03 Jan 2001 00:55:23 [EMAIL PROTECTED] wrote:
| >I've tried a slew of different things, none of which have worked.
| >Basically, if I could tell sed to only replace whole words, I'd be set.
| In perl, the \b construct denotes a word border. So /\bWORD\b/ should find
| WORD by itself (if the same works with sed).

It doesn't. However, one trick I've used a lot for this kind of thing is to
first add a space at the start and end of the line, then to go

        s/ theword / somethingelse /

(i.e. _require_ spaces each side, which I've handily arranged at the
start and end as well), then to rip the spaces off again afterwards.

So:

        s/^/ /
        s/$/ /
        s/ theword / somethingelse /
        s/^ //
        s/ $//

Cheers,
--
Cameron Simpson, DoD#743        [EMAIL PROTECTED]    http://www.zip.com.au/~cs/

Ignorance can be cured; stupidity, on the other hand, is hereditary.
        - [EMAIL PROTECTED] (Wallace Roberts)



_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to