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 sed statements

Status
Not open for further replies.

hcclnoodles

IS-IT--Management
Jun 3, 2004
123
GB
Hi there,

I need to be able to put the hostid of my box into a file (replacing the text "enter_hostid_here" so i tried


sed -e 's/enter_hostid_here/`hostid`/g' inputfile > outputfile



but it takes the `hostid` literally as text .....how can I get this info into the file (ideally in a single line)

I notice also that you cant call $VARIABLES in sed statements either as they too are taken literally

any help would be great
Cheers
 
Either:

[tt]sed -e 's/enter_hostid_here/'`hostid`'/g' inputfile > outputfile[/tt]

or:

[tt]sed -e "s/enter_hostid_here/`hostid`/g" inputfile > outputfile[/tt]

` characters between single quotes are treated literally, so you either need to terminate and reopen the single quotes, or use double quotes.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top