shell中文本轉化爲數組的幾種方法

方法一:
for x in `awk '{print $2}' ip.txt `
{
echo $x
}

方法二:
ARRAY=($(awk '{print $2}' ip.txt))

方法三:
n=0;
while read a b;
do
array[$n]=$b;
((n++));
done<ip.txt

方法四:
n=1
while ((n<=$(cat ip.txt|wc -l)))
do
ipaddr[$n]=$(cat ip.txt|sed -n "${n}p"|awk '{print $2}')
((n+=1))
done
n=`expr $n - 1`

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章