我在想如何从主机名中删除最后一个句号。现有的输出如下:
- domain.com.
- suddomain.com.
- domain.com.
- subdomain.subdomain.com.
- subdomain.com.
- domain.com
- subdomain.com
- domain.com
- subdomain.subdomain.com
print string[:-1] #it works on some lines but not all
尝试2:
str = string.split('.')
subd = '.'.join(str[0:-1])
print subd # does not work at all
代码:
global DOMAINS
if len(DOMAINS) >= 1:
for domain in DOMAINS:
cmd = "dig @adonis.dc1.domain.com axfr %s |grep NS |awk '{print $1}'|sort -u |grep -v '^%s.$'" % (domain,domain)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
string = p.stdout.read()
string = string.strip().replace(' ','')
if string:
print string