Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3398164
  • 博文数量: 864
  • 博客积分: 14125
  • 博客等级: 上将
  • 技术积分: 10634
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-27 16:53
个人简介

https://github.com/zytc2009/BigTeam_learning

文章分类

全部博文(864)

文章存档

2023年(1)

2021年(1)

2019年(3)

2018年(1)

2017年(10)

2015年(3)

2014年(8)

2013年(3)

2012年(69)

2011年(103)

2010年(357)

2009年(283)

2008年(22)

分类: Python/Ruby

2011-09-12 10:15:48

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

方法一:
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
方法四:
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`

按行读取文件内容:
while read line
do
echo $line           
done
阅读(2354) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~