文章目录
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
|-------------|-------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 | 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脚本提取
脚本一 {#title-0}
cat ip.txt | sed -e "s/:/ /" | while read ip port do echo $ip $port # blog.whsir.com done
|---------|---------------------------------------------------------------------------------------------| | 1 2 3 4 | 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
|-------------|-------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 | 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/ / /"即可
脚本二 {#title-1}
while IPS=: read ip port; do echo $ip $port done < ip.txt
|---------|------------------------------------------------------------| | 1 2 3 4 | 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
|-------------|-------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 | 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 |