我们想用现有的旧域名替换任何域名dn.txt文件
例子:
domainName=` hostname | sed s'/\./ /g' | awk '{print $2}' `
echo $domainName
trump1
所以在这种情况下 trump1 将取代旧域名 - obbama
注意 - 变量 $domainName 可以是任何其他域名,该命令应该用旧域名替换变量值dn.txt文件
示例 - 之前:
more dn.txt
hive-site,hive.zookeeper.quorum,master01.obbama.com:2181,master02.obbama.com:2181,master03.obbama.com:2181
site,hive.zookeeper.quorum,worker01.obbama.com:2181,worker02.obbama.com:2181,worker03.obbama.com:2181
.
.
示例 - 之后 - 预期输出
hive-site,hive.zookeeper.quorum,master01.trump1.com:2181,master02.trump1.com:2181,master03.trump1.com:2181
site,hive.zookeeper.quorum,worker01.trump1.com:2181,worker02.trump1.com:2181,worker03.trump1.com:2181
答案1
sed
方法:
domainName="trump"
sed -Ee "s/[^.]+(\.com:)/${domainName}\1/g" dn.txt
输出:
hive-site,hive.zookeeper.quorum,master01.trump.com:2181,master02.trump.com:2181,master03.trump.com:2181
site,hive.zookeeper.quorum,worker01.trump.com:2181,worker02.trump.com:2181,worker03.trump.com:2181