Linux Shell下加入数组和循环输出数组的方法

2017年03月16日

原创内容,转载请注明出处: https://www.myzhenai.com.cn/post/2482.html https://www.myzhenai.com/thread-17981-1-1.html
关键词: Linux Shell 数组 循环 输出数组
这个文章的知识点是理解如何将一个文本里的所有内容逐行添加到一个数组中, 然后再循环把这个数组的每一项项目和元素输出到另一个文本中, 这方法可以用于我们提取一个文本文件中的一些内容.

# !/bin/bash
. /etc/profile
function vpnbook() {
curl -s -o vpnbook.html https://www.vpnbook.com/
x=`cat vpnbook.html | grep -A 24 'Free PPTP VPN Account' | sed '/Free PPTP VPN Account/d' | sed 's/
  • //g' | sed 's/< \/span>//g' | sed 's/< \/strong>//g' | sed 's/< \/li>/\r/g' | sed '/green/d' | sed '/< \/ul>/d' | sed '/
  • /d' | sed '/square/d' | sed 's///g' | sed 's/
  • //g' | sed 's/
  • //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 "
    " >> vpn.log rm -rf vpnbook.html } vpnbook
  •  


    sicnature ---------------------------------------------------------------------
    Your current IP address is: 54.160.243.44
    Your IP address location: 美国弗吉尼亚阿什本
    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

    没有评论

    发表回复

    您的电子邮箱地址不会被公开。 必填项已用*标注