【转载】linux shell 数组建立及使用技巧
详解请见:http://suo.iteye.com/blog/1118825
从上面讲到的,大家可以发现linuxshell的数组已经很强大了,常见的操作已经绰绰有余了。
shell按行读取并保存成数组
从ip.txt里读取IP.然后把IP地址赋值到一个数组里.
IP文件如下:
Address:220.181.26.163
Address:220.181.26.174
Address:220.181.26.175
Address:220.181.26.176
Address:220.181.19.228
Address:220.181.19.229
Address:220.181.26.161
Address:220.181.26.162
方法一:
forxin`awk'{print$2}'ip.txt`
{
echo$x
}
方法二:
ARRAY=($(awk'{print$2}'ip.txt))
方法三:
n=0;whilereadab;doarray[$n]=$b;((n++));done<ip.txt
方法四:
n=1
while((n<=$(catip.txt|wc-l)))
do
ipaddr[$n]=$(catip.txt|sed-n"${n}p"|awk'{print$2}')
((n+=1))
done
n=`expr$n-1`
相关推荐
Yyqingmofeige 2020-08-18
Zaratustra 2020-07-29
yoshubom 2020-07-18
ZoctopusD 2020-06-22
fendou00sd 2020-06-16
shelleymyl 2020-08-14
Jieen 2020-06-18
applecarelte 2020-06-04
CARBON 2020-05-18
zhushixia 2020-05-04
liujianhua 2020-04-22
Jieen 2020-04-18
伏雌摘星阁 2020-04-15
pimshell 2020-02-03
onetozero 2019-12-06
Sabrina 2019-12-08