0

my sed input is as follows:

sed 's/ListenAddress=.*/ListenAddress= $hostname/' nodemanager.properties

I am trying to run this against a Linux server and replace ListenAddress={current_value} with ListenAddress={hostname_of_server}

I need to know how to run the hostname command and have that output be reflected at the end of ListenAddress=

Thanks

aphexlog
  • 1,503
  • 3
  • 16
  • 43

1 Answers1

0

If you wish your bash variables to reflect inside the sed script use, double quotes. The same is valid for command substitution. So you should be doing

sed "s/ListenAddress=.*/ListenAddress= $(hostname)/" nodemanager.properties

Since thevariable expansion takes place, you need to be careful about certain situations where $ appear as a sed attribute. For example if you're applying the above command only to the last line of the file, then do

sed "\$s/ListenAddress=.*/ListenAddress= $(hostname)/" nodemanager.properties

Note the $ before s command is escaped meaning that it is literal $ supplied to the script.

sjsam
  • 21,411
  • 5
  • 55
  • 102