Otimização de desempenho [fechada]

4

Eu tenho um script que, aproximadamente, tem que ler 1,5 milhão de linhas e processar as linhas e imprimir a saída no arquivo cvs. Este script é atual levando mais de 8-9 horas para processar 250 mil linhas. É possível reduzir o tempo?

    ###### 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>.*,,g' | grep -v xml'
    IMSI='echo $line | grep svc_result | sed -e 's,.*<imsi>\([^<]*\)</imsi>.*,,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>.*,,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>.*,,g' | grep -v xml'
    MSC_NO='echo $line | grep svc_result | sed -e 's,.*<vmscno>\([^<]*\)</vmscno>.*,,g' | grep -v xml'
    ADD_INFO='echo $line | grep svc_result | sed -e 's,.*<add_info>\([^<]*\)</add_info>.*,,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>.*,,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
    
por aloksinghk 16.07.2016 / 11:35

0 respostas