PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > sed replace match exactly word
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

sed replace match exactly word

Réponse
 
LinkBack Outils de la discussion
Vieux 21/04/2008, 17h34   #1
ric
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Vieux 21/04/2008, 17h46   #2
ric
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sed replace match exactly word

On Apr 21, 10:34am, ric <ricar...@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 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
  Réponse avec citation
Vieux 21/04/2008, 17h52   #3
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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.

  Réponse avec citation
Vieux 21/04/2008, 20h29   #4
ric
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sed replace match exactly word

On 21 abr, 10:52, Ed Morton <mor...@lsupcaemnt.com> wrote:
> 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.


Thanks for your Ed!
-ric
  Réponse avec citation
Vieux 22/04/2008, 03h01   #5
Owen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sed replace match exactly word

On Apr 22, 2:34 am, ric <ricar...@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
  Réponse avec citation
Vieux 22/04/2008, 09h57   #6
deepak
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sed replace match exactly word

echo "for forwarded" | sed 's/for/www/'
will give u www forwarded.remove the trailing g character.
  Réponse avec citation
Vieux 22/04/2008, 12h33   #7
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h52.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,17021 seconds with 15 queries