我有一个用于进行 whois 查找的脚本:
#!/bin/bash
for domain in `cat /Users/jason/Desktop/letters.txt `; do
echo $domain >> /Users/jason/Desktop/whois-results.txt whois $domain | grep "Expiry date" >> /Users/jason/Desktop/whois-results.txt
done
这会读取域名文本文件并进行 whois 搜索
结果是:
Expiry date: 11-Jun-2016 Expiry date: 10-Jun-2024 Expiry date: 19-Aug-2016 Expiry date: 10-Jun-2015 Expiry date: 12-Jun-2016 Expiry date: 19-Aug-2016 Expiry date: 10-Jun-2016
我想要的是: 到期日期: 11-Jun-2016
a.co.uk Expiry date: 10-Jun-2024 b.co.uk Expiry date: 19-Aug-2016 c.co.uk Expiry date: 10-Jun-2015 d.co.uk Expiry date: 12-Jun-2016 e.co.uk Expiry date: 19-Aug-2016 f.co.uk Expiry date: 10-Jun-2016
换句话说,我只想将 $domain 变量添加到每行的开头。
谢谢。
答案1
添加一个-n
开关以echo
省略换行符,然后执行whois
查询:
#!/bin/bash
for domain in `cat /Users/jason/Desktop/letters.txt `
do
echo -n "$domain " >> /Users/jason/Desktop/whois-results.txt
whois $domain | grep "Expiry date" >> /Users/jason/Desktop/whois-results.txt
done