shell练习-扩展

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash

if   [ $# -eq 0  ];then
        IPLINE=`seq $(cat host.txt|wc -l)`
elif [ $# -eq 1 ];then 
        KEYVAR=`echo $1|tr "," "|"`
        IPLINE=`cat host.txt|grep -En "$KEYVAR"|awk -F ":" '{print $1}'`    
elif  [ $# -gt 1 ];then 
echo "Error! The style:$0 IP1,IP2,IP3...."
exit
fi



for i in $IPLINE
do

sed -n "$i"p host.txt

echo "-----------"

done