我正在尝试创建一个Hadoop
群集,为了做到这一点,我必须将/etc/hosts
文件格式化为只包含群集中节点的IP地址。目前它看起来像这样:
127.0.0.1 localhost
# 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
<ipaddress1> namenode
<ipaddress2> secondarynamenode
<ipaddress3> slave1
<ipaddress4> slave2
## vagrant-hostmanager-end
最后,我只想将其保留为
## vagrant-hostmanager-start
<ipaddress1> namenode
<ipaddress2> secondarynamenode
<ipaddress3> slave1
<ipaddress4> slave2
## vagrant-hostmanager-end
如何使用sed
,grep
,cat
或任何Bash
命令实现这一目标?
答案 0 :(得分:2)
只需使用这样的sed:
sed -n '/## vagrant-hostmanager-start/,/## vagrant-hostmanager-end/p' /etc/hosts
## vagrant-hostmanager-start
<ipaddress1> namenode
<ipaddress2> secondarynamenode
<ipaddress3> slave1
<ipaddress4> slave2
## vagrant-hostmanager-end