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 derfloh 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
Joined
Jun 3, 2004
Messages
123
Location
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.
 
aaaaaah thank you it works :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top