variables in sed

when i do something like substituting a particular thing with a system variable, i am unable to do that expect the varible name getting into that.

for ex.. i tried,

sed -e 's/date/`date`/g' <if >of

but i got date replaced with "`date`" and not with the actual date ..
same case happened with a variable $var.

Can I know where I go wrong?

Thanks

It's the single-quotes surrounding the s//g statement. They are there to make sure nothing sent to sed is interpretted by the shell first, and that includes back-quotes.

well, see the example..

----------------------------

sh-2.05$ cat file

date

sh-2.05$ sed "s#date#`date`#" file

Thu Jan 3 20:39:08 JAVT 2002

sh-2.05$

----------------------------

i guess that's what you mean.

Thanks LivinFree and Negative,
I got that and I wish to know more about these chatacterisations with sed. I could not find much info on

man sed

thanks again
:slight_smile:

Well, okay.. Now for completing your HAPPINESS :slight_smile:

please visit this URL, http://www.dbnet.ece.ntua.gr/~george/sed/1liners.html, i promise it will give you more info about sed.

Peace,

you can use double quotes instead of single quotes.. while using single quotes sed wont substitute value of variables, but using double quotes will substitute value..

example: sed "s/$var/" filename