# [SOLVED] sed - using an environment variable as a replacement string ???



## gwicke (Dec 19, 2001)

I would like to use 'sed' to edit a file by searching for a fixed string and replacing it with an environment variable that is dynamically set with, in this case, the current date and time.

I'm trying this format of the command:

sed 's/XXXXXX/${env_var}/' filein.txt

The command replaces the 'XXXXXX' with literally '${env_var}' and not the interpretation of the variable. I have set the variable before trying to run this command.

It appears 'sed' will only replace using literally what's between the delimiter characters.

Any way to do this?

Thanks much in advance.

Gary


----------



## codejockey (Feb 11, 2002)

Try changing your single quotes to double quotes in your sed command, and see it that helps. Double quotes allow shell expansion; single quotes protect from shell expansion. 

Hope this helps.


----------



## gwicke (Dec 19, 2001)

Hey codejockey

Thanks much for the suggestion. I actually got the same suggestion a little while ago and it worked perfectly!

I should have remembered this one. I guess my FIFO memory management system had swapped that bit of information out for something else.

Thanks again and have a great holiday season.

/g


----------

