ComfortablyNumb
12-04-2002, 09:40 AM
I would like to use an environemnt variable as a replacement string in a 'sed' command. Here is what I have so far:
rundate=$(date +"%b %d, %Y %T") #current date
# I have a text file called 'rpt.txt' that contains the string 'XXXXXX'
# as a place holder for the date field. I want to replace the X's
# with the dynamic date held in the $rundate variable.
sed 's/XXXXXX/${rundate}/' rpt.txt > newrpt.txt
I've tried several format versions of the environment variable but to no avail. I always get literally what's in the replacement field.
In this case my report ends up with 'Run Date: ${rundate}' which is abviously not what I would like.
Any help is greatly appreciated.
Long Live the Floyd!
rundate=$(date +"%b %d, %Y %T") #current date
# I have a text file called 'rpt.txt' that contains the string 'XXXXXX'
# as a place holder for the date field. I want to replace the X's
# with the dynamic date held in the $rundate variable.
sed 's/XXXXXX/${rundate}/' rpt.txt > newrpt.txt
I've tried several format versions of the environment variable but to no avail. I always get literally what's in the replacement field.
In this case my report ends up with 'Run Date: ${rundate}' which is abviously not what I would like.
Any help is greatly appreciated.
Long Live the Floyd!