Results 1 to 7 of 7
hi ,
I have a text file in which i need to replace all occurances of the word "prod" with "test". I should not replace for the substirng "prod" in ...
- 10-07-2009 #1Just Joined!
- Join Date
- Oct 2009
- Posts
- 2
sed command to replace all occurances of a word in a file
hi ,
I have a text file in which i need to replace all occurances of the word "prod" with "test". I should not replace for the substirng "prod" in a word.
for example "product" should not be replaced to "testuct"
I am using the command sed -e 's/prod/test/g' to replace all occurances of the word "prod" with "test".
but it is replacing "product" to "testuct" which i dont want.
So how should i change my sed command.
Thanks in advance
- 10-07-2009 #2Just Joined!
- Join Date
- Aug 2009
- Posts
- 76
- 10-08-2009 #3Just Joined!
- Join Date
- Jan 2007
- Location
- Tamil Nadu, India
- Posts
- 18
Hi ukbhan,
sed "s/ prod / test /g" will solve your problem.
- 10-12-2009 #4Linux Newbie
- Join Date
- Sep 2004
- Location
- UK
- Posts
- 160
try (sed -e "s/\<prod\>/test/g") eg:
echo "prod product cattleprod prod." | sed -e "s/\<prod\>/test/gIn a world without walls and fences, who needs Windows and Gates?
- 10-14-2009 #5Just Joined!
- Join Date
- Jan 2007
- Location
- Tamil Nadu, India
- Posts
- 18
- 10-14-2009 #6Linux Newbie
- Join Date
- Sep 2004
- Location
- UK
- Posts
- 160
\< = starts with and \> = ends with , used together whole word
In a world without walls and fences, who needs Windows and Gates?
- 10-14-2009 #7Just Joined!
- Join Date
- Jan 2007
- Location
- Tamil Nadu, India
- Posts
- 18
Thanks blinky.


Reply With Quote
