我们需要验证列表文件
master01.sys65.com 23.154.3.61
master02.sys65.com 23.154.3.62
master03.sys65.com 23.154.3.63
worker01.sys65.com 23.154.3.64
worker02.sys65.com 23.154.3.65
worker03.sys65.com 23.154.3.66
kafka01.sys65.com 23.154.3.85
kafka02.sys65.com 23.154.3.86
kafka03.sys65.com 23.154.3.87
规则是:
每个第一个字段中的主机名必须位于第二个字段中的 IP 地址
错误列表的示例
master01.sys65.com 23.154.3.61
master02.sys65.com 23.154.3.62
master03.sys65.com 23.154.3.63
worker01.sys65.com 23.154.3.64
worker02.sys65.com 23.154.3.65
worker03.sys65.com
kafka01.sys65.com 23.154.3.85
kafka02.sys65.com 23.154.3.86
kafka03.sys65.com 23.154.3.87
or
master01.sys65.com 23.154.3.61
master02.sys65.com 23.154.3.62
master03.sys65.com 23.154.3.63
worker01.sys65.com 23.154.3.64
worker02.sys65.com 23.154.3.65
23.154.3.66
kafka01.sys65.com 23.154.3.85
kafka02.sys65.com 23.154.3.86
kafka03.sys65.com 23.154.3.87
答案1
Awk
解决方案:
awk 'NF == 1{ f=1; exit }END{ print "Hostname list is "(f? "not ":"")"valid" }' file