shell 按行读取并保存成数组
2012-11-15 15:42
357 查看
博主:http://mark-ztw.iteye.com/blog/1535480
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
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`
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
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`
相关文章推荐
- shell脚本----读取一个文本文件将内容按行保存成数组变量
- shell脚本从文件中按行读取数据,并且赋值到数组中的几种方法
- C++按行读取文件内容,储存在数组中
- IOS中的结构体保存到数组与读取
- 记录一个问题---php序列化一个数组保存到数据库中,读取之后反序列化出错
- Unity3D 中PlayerPrefs保存或读取字符串数组的脚本方法
- php读取csv数据保存到数组的方法
- shell脚本-----按行读取文件
- shell脚本按行读取文件并解析
- 用vc读取数据库的字段值,保存在数组里
- shell脚本按行读取文件并解析
- IOS中的结构体保存到数组与读取
- Unity3D 中保存或读取数组的方法
- Unity3D 中PlayerPrefs保存或读取数组的方法
- shell脚本按行读取文本文件,并对读取的行进行分析
- iOS 结构体 定义变量注意事项以及保存到数组与读取
- PHP fgets按行读取字符串和explode分割字符串为数组
- Unity3D 中PlayerPrefs保存或读取数组的方法
- Numpy数组的保存与读取
- IOS中的结构体保存到数组与读取