syntax for variables in sed

I always kind of wondered this but I have a variable that I want to use in a search and replace. Basically I want to search a file for the string in my variable and replace it with something fixed but I'm unsure of the variable rule in sed. Here's generally what I have:

sed 's/$name/newname/g' file

Not sure if $name needs to be escaped or something. This always confuses me so if someone could help that'd be awesome! Many thanks!

Just remove the single quotes so that the interpolation will happen.

sed s/$name/newname/g file

ah ok cool thanks! But one more problem and i believe it has to do with something im substituting in. The variable $name contains something like... "<stuff>morestuff" without the quotes of course. I think the sed command is getting killed by the <> brackets though. Any fix for this? thanks!

You can make use of backslashes(\) to negate the meaning.
If you still have doubts,revert back with proper requirement ....

so i've tried the following:

sed 's/\$name/newname/g' file

and

sed 's/\$name\/newname/g' file

which doesn't error out but doesn't do anything either. I think the problem is that the variable I'm subbing in @name is of the following format:

<stuff> more stuff

So the second > isn't being escaped. Not sure if this needs to be parsed or what I can do to fix that

sed "s/${name}/newname/g" file

Hmm, seems to be giving me this problem now:

bad flag in substitute command: 'r'

I tried with and without the double quotes. I tried with single quotes around the sed and that didnt seem to do anything. Not sure if it mattered but the line before this sed command I also set the name variable to something so this isn't a variable being passed in

what's the value of '${name}' variable?

It's something with this syntax:

<ticket://abc/43289324> hdsbdkdsa

sed "s#${name}#newname#g" file

thanks but still no luck. What did you mean by the red # symbol?

'no luck' as in..... ? What errors are you getting?
run your shell script in 'debug' (set -x) and post a sample output using the vB Codes.

can you try using this ::

cat filename | sed s-$var-XXX-g

Hope it will work

no luck as in it didn't do anything. no error and didn't produce the right result. I'll paste the script so maybe u can see if other things are causing issues

#!/bin/sh
name=$(grep ENGINE radar)
echo ${name}
sed "s#${name}#ENGINE#g" template> output

The word ENGINE is what I want to replace in file template with whatever gets put into the $name variable. the result right now is that output is the same file as template

please check your sed command is syntactically incorrect.

sed s/oldword/newword/g

Please change the position of variable in ur command e.g :
sed "s#ENGINE#${name}#g" template> output

Ahh that's what it was! Good catch! Thanks everyone for all the help =D