#!/bin/bash
#Author Xsh date:08-15-2006
echo "Time:$(date)==>Strat to processing........." #显示程序开始运行时间
while read numseg
do
tmplow="${tmplow} $(expr substr ${numseg} 1 10 & >/dev/null ) "
tmptop="${tmptop} $(expr substr ${numseg} 12 10 & >/dev/null ) "
done < ./numseg.txt #循环读取号段文件下限号段存入变量tmplow,上限号段存入变量tmptop
arr_lownug=(${tmplow}) #将下限号段存入数组arr_lownug
arr_topnug=(${tmptop}) #将上限号段存入数组arr_topnug
#定义函数checknum(),输入参数为需要检查的"计费号码",输出参数为0或者1
#函数checknum()输出为0 表示"计费号码" 不在号段文件的所有号段范围内
#函数checknum()输出为1 表示"计费号码" 在号段文件的所有号段范围内
#函数checknum()中用二分搜索法进行号码的判断
checknum(){ #函数定义开始
thisnum=$1
ckresult=0
lowflag=0
topflag=$((${#arr_lownug[*]} - 1 )) #标注1
MaxIndex=$((${#arr_topnug[*]} - 1 )) #标注2
midflag=0
midflag=$((${topflag} / 2 )) #标注3
if [ "${thisnum}" \< "${arr_lownug[0]}" -o "${thisnum}" \> "${arr_topnug[${MaxIndex}]}" ]
then
return 0
else
while [ "$lowflag" != "$midflag" ]
do
if ["$thisnum"\> "${arr_lownug[${midflag}]}" -o "$thisnum" == \
"${arr_lownug[${midflag}]}"]
then
lowflag=${midflag}
midflag=$(( $((${topflag} + ${lowflag})) / 2 )) #标注4
elif["$thisnum"\<"${arr_lownug[${midflag}]}" -o "$thisnum" == \
"${arr_lownug[${midflag}]}"]
then
topflag=${midflag}
midflag=$(($((${topflag} + ${lowflag})) / 2 )) #标注5
else
echo "Error!"
fi
done
if ["$thisnum" \< "${arr_topnug[${lowflag}]}" -o "$thisnum" == \
"${arr_topnug[${lowflag}]}"]
then
return 1
else
return 0
fi
fi
}#函数定义结束
while read f
do
org="${f:0:10}" #标注6
checknum ${org}
returnval=$?
if [ "$returnval" == "1" ]
then
echo "${f}" >> ./Match_result.cdr #将匹配的记录存入结果文件1
else
echo "${f}" >> ./NoMatch_result.cdr #将不匹配的记录存入结果文件2
fi
done < ./rttest.txt
echo "Time:$(date) ==> Proccess is end! "
exit 0;