Python getent主机的首字母为3位数+;主机名unix

Python getent主机的首字母为3位数+;主机名unix,python,awk,sed,cut,Python,Awk,Sed,Cut,我需要前3个八位字节的IP地址和myhosts名称,而我正试图通过cut命令创建,但无法加入主机名 $ getent hosts myhosts 172.10.2.32 myhosts.lab.com 任何带有awk、sed、cut和python的东西都可以 $ getent hosts myhosts | cut -d "." -f1,2,3 172.10.2 输出应为: 172.10.2 myhosts.lab.com 在第一个字段中,删除最后一个点的所有内容: $ awk '

我需要前3个八位字节的IP地址和myhosts名称,而我正试图通过cut命令创建,但无法加入主机名

$ getent hosts myhosts
172.10.2.32    myhosts.lab.com
任何带有awk、sed、cut和python的东西都可以

$ getent hosts myhosts | cut -d "." -f1,2,3
172.10.2
输出应为:

172.10.2  myhosts.lab.com

在第一个字段中,删除最后一个点的所有内容:

$ awk '{sub(/\.[^.]*$/,"",$1); print $1, $2}' <<< "172.10.2.32    myhosts.lab.com"
172.10.2 myhosts.lab.com

$awk'{sub(/\..[^.]*$/,”,$1);print$1,$2}'
$sed-E's/\.[0-9]++/'我对它进行了如下编辑,得到了相同的输出<代码>{$getenthosts myhosts | awk'{sub(/\.[^.]*$/,“”,$1);print$0}'172.10.2 myhosts.lab.com}
如果possible@KarnKumar解释added@fedorquie .. 非常感谢。非常好的Sed解决方案,谢谢。
$ sed -E 's/\.[0-9]+ +/ /' <<< '172.10.2.32    myhosts.lab.com'
172.10.2 myhosts.lab.com
$ sed -E 's/\.[0-9]+[[:blank:]]+/ /' <<< '172.10.2.32    myhosts.lab.com'
172.10.2 myhosts.lab.com