标签:test2 -- ip cat shell txt root 255
shell脚本–筛选出合法ip地址
作者:蓝眼泪
#!/bin/bash
grep "^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$" /root/ip.txt >/root/ip_test1.txt
line=$(wc -l /root/ip_test1.txt |awk '{print $1}')
echo "" >/root/ip_test.txt
for (( i=1;i<=$line;i=i+1 ))
do
cat /root/ip_test1.txt |awk ' NR=="$i" {print} ' >/root/ip_test2.txt
a=$( cat /root/ip_test2.txt |cut -d "." -f 1 )
b=$( cat /root/ip_test2.txt |cut -d "." -f 2 )
c=$( cat /root/ip_test2.txt |cut -d "." -f 3 )
d=$( cat /root/ip_test2.txt |cut -d "." -f 4 )
if [ "$a" -lt 1 -o "$a" -gt 255 ]
then
continue
fi
if [ "$b" -lt 0 -o "$b" -gt 255 ]
then
continue
fi
if [ "$c" -lt 0 -o "$c" -gt 255 ]
then
continue
fi
if [ "$d" -lt 0 -o "$d" -gt 255 ]
then
continue
fi
cat /root/ip_test2.txt >> /root/ip_test.txt
done
# rm -rf /root/ip_test1.txt
# rm -rf /root/ip_test2.txt
标签:test2,--,ip,cat,shell,txt,root,255 来源: https://blog.csdn.net/qq_31086997/article/details/115861661
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。