Replace string in a file w/ a variable value

I am trying to replace the default home page for several mac user accounts, I wrote a script that will hunt the files down and replace them with a pre-configured set. The problem I am having is that the download destination path for the browser is hard coded into a .plist (text config file) file along with the homepage. The issue is that if I replace this file with a pre-configured version the homepage is changed successfully but the download location is then wrong and the browser won't be able to download anything.

the download path originally is something like /Users/rob/Desktop
the altered one is something like /Users/sample/Desktop

Because the /Users/sample/Desktop doesn't match the user I am replacing files for, there is a problem.

So I would like to set the location in the pre-configured file to something like /Users/[PATTERN//PATTERN]/Desktop and have the script open the text file, look for the pattern and replace it with the value of a variable called $USER_NAME which I already have holding the proper user name earlier in the script.

How can I have the script look inside the .plist file, find the pattern and replace it with a variable value?

Thanks,
Rob

Found this on another forum in case anyone is interested, seems straight forward enough.

Ok so the following works...... almost

cat sample.txt | sed -e 's/abc/xyz/' >> result.txt

The only problem is, I want to use variables instead of abc and xyz

so something like

SEARCH="REPLACETHISTEXT"
REPLACE="Hello"

cat sample.txt | sed -e 's/$SEARCH/$REPLACE/' >> result.txt

When I try this, nothing happens, are the variables not available due to the pipe? Is there a way around this?

Thanks,
Rob

SEARCH="REPLACETHISTEXT"
REPLACE="Hello"

cat sample.txt | sed -e "s/$SEARCH/$REPLACE/" >> result.txt

I actually JUST tried this as a guess and it worked. Can you tell me what difference there is between the single quotes and double quotes that fixes this?

Thanks,
Rob

perl -p -i -e 's/original text string/replacementstring/g' file