shell提取檔案中的ip和端口,我這裡提供兩個shell腳本傳參思路,可根據使用情況來更改。
現有一文本檔案ip.txt,檔案内容格式如下
1.1.1.1:801
114.114.114.114:80
8.8.8.8:81
223.5.5.5.5:82
119.29.29.29:77
180.76.76.76:888
通過shell腳本提取
腳本一
cat ip.txt | sed -e "s/:/ /" | while read ip port
do
echo $ip $port # blog.whsir.com
done
執行結果為
1.1.1.1:801
114.114.114.114:80
8.8.8.8:81
223.5.5.5.5:82
119.29.29.29:77
180.76.76.76:888
如果不想以冒号進行分隔,僅需要更改sed -e "s/ / /"即可
腳本二
while IPS=: read ip port;
do
echo $ip $port
done < ip.txt
1.1.1.1:801
114.114.114.114:80
8.8.8.8:81
223.5.5.5.5:82
119.29.29.29:77
180.76.76.76:888