Using variables in sed

From: Cohen, Laurence (Laurence_Cohen@sra.com)
Date: Wed Jan 04 2006 - 09:41:40 EST


Hello everyone!

Would anyone have a hint as to how to use a variable from the OS in sed?
For example, I want to be able to substitue the hostname of a system for
every instance of the word HOST in a file. I set the variable
$HOST=`hostname` and then run sed -e 's/HOST/$HOST/g' > filename. The
result of this is that it substitutes the string "$HOST" instead of it's
value. I even tried sed -e 's/HOST/`echo $HOST`/g' > filename, and the
result is that it substitutes the string "`echo $HOST`, which is also
not what I want. How do I get sed to understand that I'm referring to a
variable and not a string?

Thanks!

Laurence H. Cohen
ISM Unix System Administrator
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 23:38:21 EDT