我有以下/etc/hosts
文件:
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
## vagrant-hostmanager-start
10.60.63.6 dgnode-1 dgnode-1.dg.local
10.144.64.75 dgnode-2 dgnode-2.dg.local
10.226.98.24 namenode namenode.dg.local
## vagrant-hostmanager-end
当我执行以下awk
命令时,我得到:
awk 'NR==1{ips=$1} NR>1{ips=ips ", " $1} $2=="namenode"{nn=$1} END{
printf "/opt/mapr/server/configure.sh -C %s -Z %s -HS %s -N MyCluster\n",
ips, nn, nn}' /etc/hosts
我得到了:
/opt/mapr/server/configure.sh -C 127.0.0.1, , #, ::1, fe00::0, ff00::0, ff02::1, ff02::2, ff02::3, , ##, 10.60.63.6, 10.144.64.75, 10.226.98.24, ##, -Z 10.226.98.24 -HS 10.226.98.24 -N MyCluster
而不是
/opt/mapr/server/configure.sh -C 10.60.63.6, 10.144.64.75, 10.226.98.24 -Z 10.226.98.24 -HS 10.226.98.24 -N MyCluster
我想要的是哪个。除了127.0.0.1
之外,它只是IP地址。我怎样才能做到这一点?
答案 0 :(得分:1)
也许你应该说你只是在寻找IPv4地址,因为fe00 :: 0是一个有效的IPv6地址。我正在添加第一行:
egrep '^[0-9]' /etc/hosts | grep -v 127.0.0.1 | \
awk 'NR==1{ips=$1} NR>1{ips=ips ", " $1} $2=="namenode"{nn=$1} END{
printf "/opt/mapr/server/configure.sh -C %s -Z %s -HS %s -N MyCluster\n",
ips, nn, nn}'
产生
/opt/mapr/server/configure.sh -C 10.60.63.6, 10.144.64.75, 10.226.98.24 -Z 10.226.98.24 -HS 10.226.98.24 -N MyCluster
我不知道mapr
,但大多数参数解析库都会查找只是一个逗号,没有逗号空间,所以你可能需要更改为{{1生产:
{ips=ips "," $i}