我想要类似的东西对此:
cat infile | xargs -I {} -P3 curl {} -o /dev/null --silent --head --write-out "%{http_code} {}\n" > outfile
但使用此脚本(即包含 xargs 来启动多个查询):
for ip in `cat infile`; do
for sub in "" "www." "ftp."; do
host -t a "${sub}${ip}";
done
done | grep address | awk '{ print $4 }' > out
输入文件:
google.com
facebook.com
输出文件:
172.217.172.14
172.217.30.196
157.240.6.35
31.13.67.35
答案1
使用 xargs 你可以调用 bash 来做你想做的事
cat infile \
| xargs -I {} -P3 bash -c 'for sub in "" "www." "ftp."; do host -t a "${sub}{}" ; done '
在此命令之上,您可以添加您想要的内容
cat infile \
| xargs -I {} -P3 bash -c 'for sub in "" "www." "ftp."; do host -t a "${sub}{}" ; done ' \
| MY_POWER_FULL_SED_OR_GREP
或者如果你想将 grep 添加到 bash 命令中
cat infile \
| xargs -I {} -P3 bash -c 'for sub in "" "www." "ftp."; do host -t a "${sub}{}" ; done | MY_POWER_FULL_SED_OR_GREP '