--- On Mon, Jun 22, 2009 at 4:45 PM, Vandan Joshi<vandan...@in.com> wrote:
| So, wt shud i do to replace only 'sample' ?? not with '.' or '-' chars .....
| ????
\--
Maybe?
$ sed 's/ sample /image/gi' sample.txt
SK
--
Shakthi Kannan
http://www.shakthimaan.com
This is perfect. Small correction
bhavin mehta wrote:
> Hi
> sed 's/\<sample\>/image/ig' sample.txt
when you use "i" means ignore case if you want to match exact word do
not use "i"
--
Nilesh Vaghela
ElectroMech
Redhat Channel Partner and Training Partner
Ahmedabad: 404,Maulik Arcad,Nr. Mansi cross Road,Satellite Rd
Baroda : 25, The Emperor, Fatehgunj
www.electromech.info
hi , use this syntax sed -e '1s/sample/image/g' , it wil replace 1st occurance of pattern . Regards Vilash Jagani --- On Mon, 6/22/09, Nilesh J. Vaghela <elect...@electromech.info> wrote: |
--- On Tue, Jun 23, 2009 at 10:51 AM, vilas
jagani<vilas_ja...@yahoo.com> wrote:
| use this syntax sed -e '1s/sample/image/g' , it wil replace 1st occurance of
| pattern .
\--
Because you know that the matched pattern is occurring first, you are
suggesting the above. That may not be the case, everytime.
You are correct.
> hello friends,
>
> This is my sample.txt file
> -------------
> (1) this is sample
> (2) that is also a sample.11
> (3) here is sample-22
> (4) i am no gg.sample
> (5) i am no sample_ee
> -------------
Actually the special char are considered as end or start of the words.
Let me check and let you know.
Hi
sorry it was typing mistake
use this command
sed -i 's/sample/image/g' sample.txt
---------- Original message ----------
From:Nilesh J. Vaghela< elect...@electromech.info >
Date: 23 Jun 09 00:05:19
Subject: [VGLUG] Re: how to match exact word in sed ?
To: VG...@googlegroups.com
Hi,
This is perfect. Small correction
bhavin mehta wrote:
> Hi
> sed 's/\/image/ig' sample.txt
--- On Tue, Jun 23, 2009 at 7:01 PM, Vandan Joshi<vandan...@in.com> wrote:
| ur suggested command is not working 4 me.
\--
I thought I already gave you the solution:
$ sed 's/ sample /image/gi' sample.txt
There is a space on either side of 'sample'.
---------- Original message ----------
From:Shakthi Kannan< shakt...@gmail.com >
Date: 23 Jun 09 19:05:22
Subject: [VGLUG] Re: how to match exact word in sed ?
To: VG...@googlegroups.com
Hi Vandan:
--- On Tue, Jun 23, 2009 at 7:01 PM, Vandan Joshi wrote:
| ur suggested command is not working 4 me.
\--
I thought I already gave you the solution:
$ sed 's/ sample /image/gi' sample.txt
There is a space on either side of 'sample'.
SK
--
Shakthi Kannan
http://www.shakthimaan.com
Vandan Joshi wrote:
Should not work.
>
> hey shakthimaan,
> thnx 4 the ans but its not working 4 me here
>
> i m using RHEL-5
>
> below is my output
>
> =========================================================
> [root@localhost Desktop]# sed -e 's/ sample /image/gi' sample.txt
> this is sample
> sample is sample
> that is sample.test
> i am 11-sample
> hu ha sample.33
> ha ha hya ha sample-testing
> [root@localhost Desktop]#
> =========================================================
as sample.test REGEX consider it as a two word.
Similler for all others which includes "-" , "." etc.
So including space is not solution because than the simple "sample" word
will also not match if it start or end without space.
:(
Interesting one as always with Mr. Vandan !!
--- On Wed, Jun 24, 2009 at 1:17 AM, Nilesh J.
Vaghela<elect...@electromech.info> wrote:
| So including space is not solution because than the simple "sample" word
| will also not match if it start or end without space.
|
| :(
\--
Right. I had used a file where 'sample' had a space on either side,
and hence thought it will work in all cases! Anyways, put the
following in a file, say, sed.txt:
=== sed.txt ===
s/[[:space:]]\+sample[[:space:]]\+/ image /gi
s/[[:space:]]\+sample$/ image/gi
s/^sample[[:space:]]\+/image /gi
=== END ===
The first will match " sample ". The second will match " sample" at
the end of the line. The third will match "sample " if it begins from
a new line. Now invoke your sed using:
sed -f sed.txt sample.txt
:)
Working great.
Shakthi Kannan wrote:
> Hi,
>
> --- On Wed, Jun 24, 2009 at 1:17 AM, Nilesh J.
> Vaghela<elect...@electromech.info> wrote:
> | So including space is not solution because than the simple "sample" word
> | will also not match if it start or end without space.
> |
> | :(
> \--
>
> Right. I had used a file where 'sample' had a space on either side,
> and hence thought it will work in all cases! Anyways, put the
> following in a file, say, sed.txt:
>
> === sed.txt ===
>
> s/[[:space:]]\+sample[[:space:]]\+/ image /gi
> s/[[:space:]]\+sample$/ image/gi
> s/^sample[[:space:]]\+/image /gi
>
> === END ===
>
The perfect solution !!!!
---------- Original message ----------
From:Nilesh J. Vaghela< elect...@electromech.info >
Date: 24 Jun 09 16:19:47
Subject: [VGLUG] Re: how to match exact word in sed ?
To: VG...@googlegroups.com
Hi,
:)
Working great.
Shakthi Kannan wrote:
> Hi,
>
> --- On Wed, Jun 24, 2009 at 1:17 AM, Nilesh J.
Vandan Joshi wrote:
>
> Thnk u nilesh sir,
>
No , thanks to Mr. Shakthi :).
> Shakthi Kannan wrote:
> > Hi,
> >
> > --- On Wed, Jun 24, 2009 at 1:17 AM, Nilesh J.
> > Vaghela wrote:
> > | So including space is not solution because than the simple
> "sample" word
> > | will also not match if it start or end without space.
> > |
> > | :(
> > \--
> >
> > Right. I had used a file where 'sample' had a space on either side,
> > and hence thought it will work in all cases! Anyways, put the
> > following in a file, say, sed.txt:
> >
> > === sed.txt ===
> >
> > s/[[:space:]]\+sample[[:space:]]\+/ image /gi
> > s/[[:space:]]\+sample$/ image/gi
> > s/^sample[[:space:]]\+/image /gi
> >
> > === END ===
>
He had given the perfect solution.
Thanks to Shakthi.
---------- Original message ----------
From:Nilesh J. Vaghela< elect...@electromech.info >
Date: 24 Jun 09 22:02:28
Subject: [VGLUG] Re: how to match exact word in sed ?
To: VG...@googlegroups.com