性能优化

性能优化

我有一个脚本,大约需要读取 150 万行并处理这些行并在 cvs 文件中打印输出。该脚本当前需要 8-9 个小时以上才能处理 25 万行。是否可以减少时间?

    ###### Start Reading Line by Line When IMSI is available ##########################
    IFS=$'\n'     # new field separator, the end of line
    for line in `cat temp_req`
    do
    #printf "Line: "$line
    #printf "\n=============================================================================================\n"
    ### MSISDN , IMSI , Circle ID #####
    MSISDN=`echo $line | grep svc_result | sed -e 's,.*<msid type="MSISDN" enc="ASC">\([^<]*\)</msid>.*,\1,g' | grep -v xml`
    IMSI=`echo $line | grep svc_result | sed -e 's,.*<imsi>\([^<]*\)</imsi>.*,\1,g' | grep -v xml`
    ###### Check IMSI is Blank or Not #############
    if [ ! -z $IMSI ];then
    CIRCLE=`echo ${IMSI:0:5}`
    CIRCLE_NAME=`cat mapping | grep $CIRCLE | awk -F' ' '{print $1}'`
    ############## Getting Details By Circle One ######################################################
    if [ ! -z $CIRCLE ] && [ $CIRCLE = 40496 ]   ## HR If start
    then
    ### Check Request Status ###
    LAT=`echo $line | grep svc_result | sed -e 's,.*<X>\([^<]*\)</X>.*,\1,g' | grep -v xml`
    if [ "x$LAT" = "x"  ]
    then
    ### Get Error Status , Time , NDC, MSC, Additional Info ####
    TIME=`echo $line | grep -i svc_result | awk -F'[][]' '{print $2}'`
    ERROR_CODE=`echo $line | grep svc_result | awk -F '=' '{print $7}' | awk -F '>' '{print $1}' | tr  -s '"' ' ' | awk -F' ' '{print $1}'`
    ERROR_DESC=`echo $line | grep svc_result | awk -F '=' '{print $7}' | awk -F '>' '{print $2}' | awk -F'<' '{print $1}'`
    NDC=`echo $line | grep svc_result | sed -e 's,.*<ndc>\([^<]*\)</ndc>.*,\1,g' | grep -v xml`
    MSC_NO=`echo $line | grep svc_result | sed -e 's,.*<vmscno>\([^<]*\)</vmscno>.*,\1,g' | grep -v xml`
    ADD_INFO=`echo $line | grep svc_result | sed -e 's,.*<add_info>\([^<]*\)</add_info>.*,\1,g' | grep -v xml | awk -F';' '{print $2}'`
    ############## Validate MSC GT and ADD Info Parameter ##############
    if [ '91$MSC_NO' = '91' ];then 
    MSC_NO="0"
    fi
    if [ 'x$ADD_INFO' = 'x' ];then
    ADD_INFO=`echo $line | grep svc_result | sed -e 's,.*<add_info>\([^<]*\)</add_info>.*,\1,g' | grep -v xml | awk -F';' '{print $1}'`
    fi
    ################# Finished Validation #################
    ######################## Create Error Report ###########
    if [ ERROR$ERROR_CODE = ERROR1 ];then
    HR_ERROR1=`expr $HR_ERROR1 + 1`;HR_FAILED_COUNT=`expr $HR_FAILED_COUNT + 1`
    elif [ ERROR$ERROR_CODE = ERROR2 ];then
    HR_ERROR2=`expr $HR_ERROR2 + 1`;HR_FAILED_COUNT=`expr $HR_FAILED_COUNT + 1`
    elif [ ERROR$ERROR_CODE = ERROR3 ];then
    HR_ERROR3=`expr $HR_ERROR3 + 1`;HR_FAILED_COUNT=`expr $HR_FAILED_COUNT + 1`
    elif [ ERROR$ERROR_CODE = ERROR4 ];then
    HR_ERROR4=`expr $HR_ERROR4 + 1`;HR_FAILED_COUNT=`expr $HR_FAILED_COUNT + 1`
    elif [ ERROR$ERROR_CODE = ERROR5 ];then
    HR_ERROR5=`expr $HR_ERROR5 + 1`;HR_FAILED_COUNT=`expr $HR_FAILED_COUNT + 1`
    elif [ ERROR$ERROR_CODE = ERROR6 ];then
    HR_ERROR6=`expr $HR_ERROR6 + 1`;HR_FAILED_COUNT=`expr $HR_FAILED_COUNT + 1`
    elif [ ERROR$ERROR_CODE = ERROR202 ];then
    HR_ERROR202=`expr $HR_ERROR202 + 1`;HR_FAILED_COUNT=`expr $HR_FAILED_COUNT + 1`
    elif [ ERROR$ERROR_CODE = ERROR203 ];then
    HR_ERROR203=`expr $HR_ERROR203 + 1`;HR_FAILED_COUNT=`expr $HR_FAILED_COUNT + 1`
    elif [ ERROR$ERROR_CODE = ERROR501 ];then
    HR_ERROR501=`expr $HR_ERROR501 + 1`;HR_FAILED_COUNT=`expr $HR_FAILED_COUNT + 1`
    fi
    else
    #print $SUCCESS_COUNT
    HR_SUCCESS_COUNT=`expr $HR_SUCCESS_COUNT + 1`
    fi  
    fi
    done

相关内容