doubt in sed cmd

Page 2 of 2 Previous  1, 2

Go down

doubt in sed cmd - Page 2 Empty Re: doubt in sed cmd

Post by deepika on Mon Mar 08, 2010 5:46 pm

ya ya.. i know.. by mistake i hav sent the same.... i had the same doubt wat he had... now its fine.. it works Smile

deepika

Posts : 3
Points : 3
Join date : 2010-03-04
Age : 31
Location : chennai

View user profile

Back to top Go down

doubt in sed cmd - Page 2 Empty Re: doubt in sed cmd

Post by lalitha on Mon Mar 08, 2010 6:11 pm

wats the dfference bet sed 's/lamb/ham/g' bbbb.txt and 's/lamb/ham/' bbbb.txt
[335848@oracleclient ~]$ cat>bbbb.txt
mlamb lambd
ddss
lamb lamb
ggg lambg
[335848@oracleclient ~]$ sed 's/lamb/ham/' bbbb.txt
mham lambd
ddss
ham lamb
ggg hamg
[335848@oracleclient ~]$ sed 's/lamb/ham/g' bbbb.txt
mham hamd
ddss
ham ham
ggg hamg
i didnt get the logic

lalitha

Posts : 14
Points : 16
Join date : 2010-03-08

View user profile

Back to top Go down

doubt in sed cmd - Page 2 Empty Re: doubt in sed cmd

Post by deepika on Mon Mar 08, 2010 6:22 pm

sed 's/lamb/ham/g' bbbb.txt
In dis case g means global, so it replaces the word lamb where ever it finds...
sed 's/lamb/ham/' bbbb.txt
but here it replaces lamb oly on the first occurence in a line..

deepika

Posts : 3
Points : 3
Join date : 2010-03-04
Age : 31
Location : chennai

View user profile

Back to top Go down

doubt in sed cmd - Page 2 Empty Re: doubt in sed cmd

Post by Maithreyi on Mon Mar 08, 2010 6:28 pm

sed 's/lamb/ham/g' bbbb.txt - g stands for global replacement.It replaces all the lamb's occuring in a particular line with ham.

sed 's/lamb/ham/' bbbb.txt
whereas this replaces only the first occurence of lamb in the line with ham.Hence the difference in output!

Maithreyi

Posts : 76
Points : 142
Join date : 2010-03-03
Age : 31
Location : Haldia

View user profile

Back to top Go down

doubt in sed cmd - Page 2 Empty Re: doubt in sed cmd

Post by Sponsored content


Sponsored content


Back to top Go down

Page 2 of 2 Previous  1, 2

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum