less maskdigits.sh
#!/bin/sh
#maskdigits.sh mask
a=$(echo "$1" | awk -F "." '{print $1" "$2" "$3" "$4}')
for num in $a;
do
while (($num!=0));do
echo -n $(($num%2)) >> /tmp/$$.num;
num=$(($num/2));
done
done
echo $(grep -o "1" /tmp/$$.num | wc -l)
rm /tmp/$$.num
例如:maskdigits.sh 255.255.0.192
18
本文转自 freeterman 51CTO博客,原文链接:http://blog.51cto.com/myunix/1147611,如需转载请自行联系原作者