原创内容,转载请注明出处: http://www.myzhenai.com.cn/post/2482.html http://www.myzhenai.com/thread-17981-1-1.html
关键词: Linux Shell 数组 循环 输出数组
这个文章的知识点是理解如何将一个文本里的所有内容逐行添加到一个数组中, 然后再循环把这个数组的每一项项目和元素输出到另一个文本中, 这方法可以用于我们提取一个文本文件中的一些内容.
# !/bin/bash . /etc/profile function vpnbook() { curl -s -o vpnbook.html http://www.vpnbook.com/ x=`cat vpnbook.html | grep -A 24 'Free PPTP VPN Account' | sed '/Free PPTP VPN Account/d' | sed 's/<li><strong><span class=\"red\">//g' | sed 's/< \/span>//g' | sed 's/< \/strong>//g' | sed 's/< \/li>/\r/g' | sed '/green/d' | sed '/< \/ul>/d' | sed '/<li id=\"openvpn\">/d' | sed '/square/d' | sed 's/<span class=\"red\">//g' | sed 's/<li><strong>//g' | sed 's/<li>//g' | sed 's/\/free/http:\/\/www.vpnbook.com\/free/g'` echo ${x} >> vpn.log ik=`cat vpn.log` #导入一个文件里的所有行的文本 arr=($ik) #将所有行的文本加入数组 for i in ${arr[@]} #进入循环操作 do if [[ ${i} =~ "http:" ]]; then #如果文本中包含某些字符 d=`echo ${i} | awk -F "href=" '{ print $2 }' | awk -F ">" '{ print $1 }' | sed 's/\"//g'` wget -q -P freevpn/ ${d} #下载文件到指定目录下 fi done sed -i 's#http:\/\/www.vpnbook.com\/free-openvpn-account\/#http:\/\/www.myzhenai.com.cn\/openvpn\/#g' vpn.log echo "<hr />" >> vpn.log rm -rf vpnbook.html } vpnbook </li></strong></li></span></li></span></strong></li>
sicnature ---------------------------------------------------------------------
Your current IP address is: 3.231.212.98
Your IP address location: 美国 弗吉尼亚州阿什本amazon数据中心
Your IP address country and region: 美国

Your current browser is:
Your current system is:
Original content, please indicate the source:
同福客栈论坛 | 海南仙岛 | 海南乡情论坛 | JiaYu Blog
sicnature ---------------------------------------------------------------------
Welcome to reprint. Please indicate the source https://www.myzhenai.com.cn/post/2482.html
没有评论