我将ip-address存储在名为Worker1的参数中,另一个ip-address存储在SPARK_MASTER_IP中
echo $Worker1
10.100.53.185
echo $SPARK_MASTER_IP
10.100.53.218
我正在尝试更换行discovery.zen.ping.unicast.hosts:[127.0.0.1],如下线所示。
discovery.zen.ping.unicast.hosts: ["10.100.53.218","10.100.53.185"]
当我尝试使用sed使用以下命令时,Nothing更新并且没有错误。请帮我解决方案
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
谢谢!
答案 0 :(得分:3)
正如评论中所讨论的那样,逃避[
将为您解决问题,
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"]
在确认替换成功后,为就地替换添加-i
标记。