성능 최적화 [닫기]

성능 최적화 [닫기]

약 150만 줄을 읽고 처리한 후 출력을 cvs 파일로 인쇄해야 하는 스크립트가 있습니다. 현재 스크립트는 250,000개의 행을 처리하는 데 8~9시간 이상 걸립니다. 시간을 줄일 수 있나요?

    ###### 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

관련 정보