循环读取两个文档
2014-11-13有时我们需要从两个文档读取数据并做相应处理,通过shell实现。
::::::::::::::
实例1.sh
::::::::::::::
#!/bin/sh
> list.txt
MAX=`sed -n $= ip.txt`
for((i=1;i<=$MAX;i++));do ip=`sed -n ${i}p ip.txt` mac=`sed -n ${i}p mac.txt` echo arp $ip $mac >> list.txt
done
::::::::::::::
实例2.sh
::::::::::::::
#!/bin/sh
exec 3< ip.txt
exec 4< mac.txt
while read ip1 <&3 && read mac2 <&4
do
echo $ip1 $mac2
done
#!/bin/sh
exec 3< a.txt
exec 4< b.txt
exec 5 < c.txt
while read x <&3 && read y <&4 && read y <&5
do
echo $x $y $z
echo -e "$x\t$y\t$z"
done
分类:操作系统 | 标签: shell |