Reputation: 2011
I have the ip-address stored in a parameter called Worker1 and another ip-address is stored in SPARK_MASTER_IP
echo $Worker1
10.100.53.185
echo $SPARK_MASTER_IP
10.100.53.218
I am trying to replace the line discovery.zen.ping.unicast.hosts: [127.0.0.1] like below line.
discovery.zen.ping.unicast.hosts: ["10.100.53.218","10.100.53.185"]
When i try to use the below command using sed, Nothing is updated and no error. Please help me with a solution
sed -i -e "s/discovery.zen.ping.unicast.hosts: [127.0.0.1]/discovery.zen.ping.unicast.hosts: ["'$SPARK_MASTER_IP'","'$Worker1'"]/g" /etc/elasticsearch/elasticsearch.yml
Thanks!
Upvotes: 0
Views: 80
Reputation: 85570
As discussed over in the comments, escaping the [
will do the trick for you,
WORKER1="10.100.53.185"
SPARK_MASTER_IP="10.100.53.218"
sed -e 's/discovery.zen.ping.unicast.hosts: \["10.100.53.218","10.100.53.185"\]/discovery.zen.ping.unicast.hosts: \["'$WORKER1'","'$SPARK_MASTER_IP'"\]/g' file
discovery.zen.ping.unicast.hosts: ["10.100.53.185","10.100.53.218"]
Add the -i
flag for the in-place replacement, once you confirm the replacement to be happening successfully.
Upvotes: 3