I am working on aws cloud formation and trying to replace the sentence discovery.zen.ping.unicast.hosts: [127.0.0.1] using sed and json but it is not reading value stored under $SPARK_MASTER_IP $Worker1 .
discovery.zen.ping.unicast.hosts: [127.0.0.1]
discovery.zen.ping.unicast.hosts: ["10.100.53.195 ","10.100.52.124 "]
echo $Worker1
10.100.53.185
echo $SPARK_MASTER_IP
10.100.53.218
"su - root -c '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'\n",
but the output of the above command is
discovery.zen.ping.unicast.hosts: ["",""]
Pls help
I'm not sure what you're doing with all the escaping, although this should work:
sed -i 's/discovery.zen.ping.unicast.hosts: \[127\.0\.0\.1\]/discovery.zen.ping.unicast.hosts: \['\"$SPARK_MASTER_IP\"','\"$Worker1\"'\]/g'
Multi-line :
sed -i 's/discovery.zen.ping.unicast.hosts: '\
'\[127\.0\.0\.1\]/discovery.zen.ping.unicast.hosts: '\
'\['\"$SPARK_MASTER_IP\"','\"$Worker1\"'\]/g'
Result :
discovery.zen.ping.unicast.hosts: ["10.100.53.185","10.100.53.218"]
*The -e
option shouldn't be needed since there's nothing appended to the end of the command.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.