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!

Using variables in a sed command

Status
Not open for further replies.

pjb

Programmer
May 1, 2001
148
US
I am having problems using variables in a sed command.
For example, if I want to convert all ocurrances of AAA to BBB in file1 resulting if file2, I can use

sed 's/AAA/BBB/g' file1 > file2

If I try it with variables like this, it doesn't work

FROM="AAA"
TO="BBB"
sed 's/$FROM/$TO/g' file1 > file2

 
I'm not sure why though. My UNIX book even shows examples of a similar sed with single quotes.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top