how to use a variable in sed command
2 posters
how to use a variable in sed command
if a word and a file name are taken from user..now the word entered is to be replaced in the file specified by the user with another word..how to do that?
for e.g
if word entered is stored in $wrd and
filename is in $file
i tried to replace the word stored in $wrd by "hello" using the command:
sed 's/$wrd/hello/g' 0<$file
but it doesn't make changes
please suggest the answer...
for e.g
if word entered is stored in $wrd and
filename is in $file
i tried to replace the word stored in $wrd by "hello" using the command:
sed 's/$wrd/hello/g' 0<$file
but it doesn't make changes
please suggest the answer...
rujuta- Posts : 2
Points : 4
Join date : 2010-03-09
Re: how to use a variable in sed command
use double quotes to enclose search pattern.
- Code:
$ sed "s/$word/ORANGE/g" 1.txt
Re: how to use a variable in sed command
hey thank you for the solution...
rujuta- Posts : 2
Points : 4
Join date : 2010-03-09
Similar topics
» awk command doubt
» tee command doubt
» CDUP COMMAND
» What s d diff between 'sed' and 'tr' command??
» unix command!!!!
» tee command doubt
» CDUP COMMAND
» What s d diff between 'sed' and 'tr' command??
» unix command!!!!
Permissions in this forum:
You cannot reply to topics in this forum
|
|