Unix C++
Would you like to react to this message? Create an account in a few clicks or log in to continue.

how to use a variable in sed command

2 posters

Go down

how to use a variable in sed command Empty how to use a variable in sed command

Post by rujuta Mon Mar 15, 2010 7:02 pm

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...

rujuta

Posts : 2
Points : 4
Join date : 2010-03-09

Back to top Go down

how to use a variable in sed command Empty Re: how to use a variable in sed command

Post by Christopher Mon Mar 15, 2010 7:21 pm

use double quotes to enclose search pattern.

Code:
$ sed "s/$word/ORANGE/g" 1.txt
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

how to use a variable in sed command Empty Re: how to use a variable in sed command

Post by rujuta Mon Mar 15, 2010 7:27 pm

hey thank you for the solution... Very Happy

rujuta

Posts : 2
Points : 4
Join date : 2010-03-09

Back to top Go down

how to use a variable in sed command Empty Re: how to use a variable in sed command

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

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