sed replace match exactly word

Hi people,

I want find and replace a exactly word, but i'm getting this:

#echo "for forward"|sed 's/for/XXX/g'
XXX XXXward
#

I need get this:
"XXX forward"

I was searching and reading,but no luck yet,

Regards,
-ric
ric [ Mo, 21 April 2008 18:34 ] [ ID #1946492 ]

Re: sed replace match exactly word

On Apr 21, 10:34=A0am, ric <ricar... [at] gmail.com> wrote:
> Hi people,
>
> =A0I want find and replace a exactly word, but i'm getting this:
>
> #echo "for forward"|sed 's/for/XXX/g'
> XXX XXXward
> #
>
> I need get this:
> "XXX forward"
>
> I was searching and reading,but no luck yet,
>
> Regards,
> =A0 =A0-ric



#echo "FOR for forward forteen for for"|sed -e 's/for/XXX/'
FOR XXX forward forteen for for
#

but I need get this:
FOR XXX forward forteen XXX XXX



regards
-ric
ric [ Mo, 21 April 2008 18:46 ] [ ID #1946495 ]

Re: sed replace match exactly word

On 4/21/2008 11:34 AM, ric wrote:
> Hi people,
>
> I want find and replace a exactly word, but i'm getting this:
>
> #echo "for forward"|sed 's/for/XXX/g'
> XXX XXXward
> #
>
> I need get this:
> "XXX forward"
>
> I was searching and reading,but no luck yet,
>
> Regards,
> -ric

This will work with some (GNU) versions of sed:

$ echo "for forward"|sed 's/\<for\>/XXX/g'
XXX forward

Ed.
Ed Morton [ Mo, 21 April 2008 18:52 ] [ ID #1946496 ]

Re: sed replace match exactly word

On 21 abr, 10:52, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
> On 4/21/2008 11:34 AM, ric wrote:
>
> > Hi people,
>
> > =A0I want find and replace a exactly word, but i'm getting this:
>
> > #echo "for forward"|sed 's/for/XXX/g'
> > XXX XXXward
> > #
>
> > I need get this:
> > "XXX forward"
>
> > I was searching and reading,but no luck yet,
>
> > Regards,
> > =A0 =A0-ric
>
> This will work with some (GNU) versions of sed:
>
> $ echo "for forward"|sed 's/\<for\>/XXX/g'
> XXX forward
>
> =A0 =A0 =A0 =A0 Ed.

Thanks for your help Ed!
-ric
ric [ Mo, 21 April 2008 21:29 ] [ ID #1946500 ]

Re: sed replace match exactly word

On Apr 22, 2:34 am, ric <ricar... [at] gmail.com> wrote:
> Hi people,
>
> I want find and replace a exactly word, but i'm getting this:
>
> #echo "for forward"|sed 's/for/XXX/g'
> XXX XXXward
> #
>
> I need get this:
> "XXX forward"
>
> I was searching and reading,but no luck yet,
>
> Regards,
> -ric

echo "for forward"|sed 's/for /XXX /g'

Thats substitute for + the space with XXX + the space


Owen
xemoth [ Di, 22 April 2008 04:01 ] [ ID #1947268 ]

Re: sed replace match exactly word

echo "for forwarded" | sed 's/for/www/'
will give u www forwarded.remove the trailing g character.
deepak [ Di, 22 April 2008 10:57 ] [ ID #1947273 ]

Re: sed replace match exactly word

On 4/22/2008 3:57 AM, deepak wrote:

[This usenet, not a web forum. Please provide enough context from the post
you're replying to so your post stands alone. Fixed below]

> On 4/21/2008 11:34 AM, ric wrote:
>> Hi people,
>>
>> I want find and replace a exactly word, but i'm getting this:
>>
>> #echo "for forward"|sed 's/for/XXX/g'
>> XXX XXXward

> echo "for forwarded" | sed 's/for/www/'
> will give u www forwarded.remove the trailing g character.

That won't work on all the words in the input line and will wrongly match longer
words that contain "for" if they appear earlier in the line. Read the previous
responses in the thread for the solution (and, just a suggestion, but in future
it's worth reading the previous responses before posting yours...).

Ed.
Ed Morton [ Di, 22 April 2008 13:33 ] [ ID #1947274 ]
Linux » comp.unix.shell » sed replace match exactly word

Vorheriges Thema: Remote Shell Execution Problem
Nächstes Thema: comp.unix.shell charter