Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sed question

Status
Not open for further replies.

pmcmicha

Technical User
May 25, 2000
353
I am having a problem with variables when using sed.

For example:

VAR2=`echo ${VAR0}|/usr/bin/cut -d "_" -f2`
VAR3=`echo ${VAR1}|/usr/bin/cut -d "_" -f2`

/usr/bin/sed 's/${VAR2}/${VAR3}/g' FILE > TEMP

sed isn't liking the substitution variables I am providing. No odd characters exist in these variables and I am able to successfully execute this if I use real letters instead. I can't use real letters though since these variables will be changing from time to time and I have to modify all the files within a directory.

I also tried leaving the braces off, but this did not help and I tried a backslash in front of the dollar signs as well, but again, no effect.

Does anyone have any ideas? Thanks in advance.
 
Use double quotes instead of single quotes around the sed substitution string. Single quotes protect the variables from being expanded by the shell and you need them to be expanded.

usr/bin/sed "s/${VAR2}/${VAR3}/g" FILE > TEMP CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top