##/bin/bash
IP=($(grep -E -v "127.0.0.1|::" /etc/hosts | awk '{print $1}'))
NAME=($(grep -E -v "127.0.0.1|::" /etc/hosts | awk '{print $2}'))
Num=`grep -E -v "127.0.0.1|::" /etc/hosts|wc -l`
for i in $(seq $Num)
do
echo "${IP[i-1]}-${NAME[i-1]}"
done
转载于:https://blog.51cto.com/8789878/1770867