Q:

how to replace domain name in file

We want to replace any domain name with old domain name that exists in dn.txt file
example:
domainName=`  hostname | sed s'/\./ /g' | awk '{print $2}' `
echo $domainName
trump1

so in this case trump1 will replace the old domain name - obbama
note - variable $domainName could be any other domain name , the command should replace variable value with old domain name in dn.txt file
example - before:
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

. 
. 

example - after - expected output
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

A:

sed approach:
domainName="trump"
sed -Ee "s/[^.]+(\.com:)/${domainName}\1/g" dn.txt

The output:
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

