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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get sed to use variable values? 1

Status
Not open for further replies.
Dec 12, 2007
19
0
0
US
I have this statement that uses sed

echo $tabname | sed 's/\_NEW/\_"${Month}"\_${Day}\_${Year}\_OLD/g' | read oldtabnamesuffix

The value of oldtabnamesuffix is tablename_${Month}_${Day}_${Year}_OLD after this statement executes.

Hoe do I get sed to use the variable values?

For example, I'd like to see oldtabnamesuffix's value be tablename_07_14_2010_OLD if today's date is 07_14_2010 and I put this into the $Month, $Day and $Year variables from the date command.

Thanks
 
echo $tabname | sed "s/_NEW/_${Month}_${Day}_${Year}_OLD/g" | read oldtabnamesuffix

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
[tt]$[/tt] has no meaning inside single quotes.

Try your sed command between double quotes

OR

"interrupt" your singly-quoted sed command string whenever you need to insert a shell variable

echo $tabname | sed 's/\_NEW/\_[red]'[/red]${Month}[red]'[/red]\_[red]'[/red]${Day}[red]'[/red]\_[red]'[/red]${Year}[red]'[/red]\_OLD/g'

and I think you're over-escaping characters \_ ???

echo $tabname | sed 's/_NEW/_[red]'[/red]${Month}[red]'[/red]_[red]'[/red]${Day}[red]'[/red]_[red]'[/red]${Year}[red]'[/red]_OLD/g'


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top