linux 替换文件中的字符串
原创
©著作权归作者所有:来自51CTO博客作者liuyunshengsir的原创作品,请联系作者获取转载授权,否则将追究法律责任
代码
#! /bin/bash
master=$MASTER
slaves=$SLAVES
arrs=(${slaves//,/ })
#config /etc/hadoop/conf/core-site.xml,yarn-site.xml
sed -i "/MASTER/s/MASTER/$master/g" /etc/hadoop/conf/core-site.xml
sed -i "/MASTER/s/MASTER/$master/g" /etc/hadoop/conf/yarn-site.xml
#config /etc/hadoop/conf/workers
#先清空然后写入
: > /etc/hadoop/conf/workers
for item in ${arrs[@]}
do
echo $item>> /etc/hadoop/conf/workers
done