: !/bin/sh carrier="OPTUS" month="$1" infile="$2" #adjmonth=$month #adjmonth=`../../../adjmonth $month` #datadirpat=`echo "$adjmonth" | awk '{ print "??" substr($1,1,2) substr($1,5,2) }'` #echo "$0: datadirpat=[$datadirpat]" #infile=`ls ${datadirpat}/*/*.bil` if [ -n "$3" ]; then outfile="$3" else outfile="${carrier}_${month}.out" fi #echo "$0: infile=[$infile] outfile=[$outfile]" rm -f $outfile #rplcomma <$infile | sed -e 's/^"//;s/","/|/g;s/ $//;s/"$//;s/,/;/g' "$infile" | \ awk -F "|" -v "billmonth=$month" -v"carrier=${carrier}" ' function trim(is) { #sub(/^\"/,"", is) #sub(/\"$/,"", is) while (sub(/^ /, "", is) != 0) is = is "" while (sub(/ $/, "", is) != 0) is = is "" return is } ##################################################### # main BEGIN { monthstr[1] = "Jan"; monthstr[2] = "Feb"; monthstr[3] = "Mar"; monthstr[4] = "Apr"; monthstr[5] = "May"; monthstr[6] = "Jun"; monthstr[7] = "Jul"; monthstr[8] = "Aug"; monthstr[9] = "Sep"; monthstr[10] = "Oct"; monthstr[11] = "Nov"; monthstr[12] = "Dec"; billmm = 0 + substr(billmonth,1,2) billyyyy = 0 + substr(billmonth,3,4) billperiod = monthstr[billmm] " " billyyyy } { gsub(/\r/, "") # remove CR gsub(/\032/, "") # remove FF linetype = trim($2) #if ( linetype == "253500" ) { if ( linetype == "250500" ) { billdate = trim($4) servicenumber = trim($6) next } if ( linetype == "353501" ) { class = trim($3) next } ################################################## # rent/call/other (based on TAS optus.pas code) # rent if (linetype == "351005" ) { linecode = trim($3) callclass = "" datestr = trim($8) yyyy = 0 + substr(datestr,1,4) mm = 0 + substr(datestr,5,2) dd = 0 + substr(datestr,7,2) from_date = sprintf("%02d/%02d/%04d", dd, mm, yyyy) datestr = trim($9) yyyy = 0 + substr(datestr,1,4) mm = 0 + substr(datestr,5,2) dd = 0 + substr(datestr,7,2) to_date = sprintf("%02d/%02d/%04d", dd, mm, yyyy) sdate_str = "CHARGE_DESC" btxt_stime_str = "000000" btxt_origin = "RENT" btxt_destination = trim($4) # description btxt_dialled = from_date " to " to_date dursecs = 0 costinclgst = 0.0 + trim($10) if ( costinclgst != 0 && (linecode == "SRVC" || linecode == "F-VM" || linecode == "F-SMS") ) { btxt_origin = "RENT" outrec() next } next } # call / other if (linetype == "350505" ) { linecode = trim($3) callclass = "" sdate_str = "CHARGE_DESC" btxt_stime_str = "000000" btxt_origin = "" # set RENT/CALL/OTHER below btxt_destination = trim($4) # description btxt_dialled = "" dursecs = 0 costinclgst = 0.0 + trim($5) ## rent #if ( costinclgst != 0 && # (linecode == "SRVC" || linecode == "F-VM" || # linecode == "F-SMS") ) { # btxt_origin = "RENT" # outrec() # next #} # call if ( costinclgst != 0 && (linecode == "U-CAL" || linecode == "U-DAS" || linecode == "U-IAR" || linecode == "F-SMC" || linecode == "F-SMT" || linecode == "PROMO") ) { btxt_origin = "CALL" outrec() next } # other if ( costinclgst != 0 && (linecode == "OCC") ) { btxt_origin = "OTHER" outrec() next } next } ################################################## # call detail if ( linetype == "353505" ) { billsection = trim($3) callclass = class " " billsection # Bill Data btxt = $0 #printf("Service Number = [%s] Call Class = [%s]\n", servicenumber, callclass); #printf("%s\n", btxt); datestr = trim($4) #yyyy = 0 + substr(datestr,1,4) # is always 0000 ??? mm = 0 + substr(datestr,5,2) dd = 0 + substr(datestr,7,2) #printf("dd=[%s] mm=[%s]\n", dd, mm); billcc = 0 + substr(billdate,1,2) billyy = 0 + substr(billdate,3,2) billmm = 0 + substr(billdate,5,2) billdd = 0 + substr(billdate,7,2) #printf("billdate=[%s]\n", billdate); #printf("billcc=[%s]\n", billcc); #printf("billyy=[%s]\n", billyy); sdate_str = sprintf("%02d/%02d/%02d%02d", dd, mm, billcc, billyy) stimestr = trim($5) btxt_stime_str = substr(stimestr,1,2) substr(stimestr,3,2) "00" btxt_origin = trim($7) btxt_destination = trim($8) btxt_dialled = trim($9) #if ( btxt_dialled == "**INCOMING*" ) # next # see whats in fields #print callclass | "sort -u >callclass.uniq" #print btxt_dialled | "sort -u >btxt_dialled.uniq" ### use unprocessed NUMBER for dest description ###btxt_destination = btxt_dialled ## process dialled number to remove inconsistencies #sub(/YES$/, "", btxt_dialled) # remove YES if ( length(btxt_dialled) >= 11 ) sub(/^61/, "0", btxt_dialled) # replace with 0 btxt_rate = trim($10) durstr = trim($14) #printf("durstr=[%s]\n", durstr); durmins = 0.0 + durstr #printf("durmins=[%s]\n", durmins); dursecs = int(durmins * 60) #printf("dursecs=[%s]\n", dursecs); btxt_cost = trim($15) costinclgst = sprintf("%0.2f", 0.0 + btxt_cost) # get dest onnet/offnet #cmd0 = sprintf("../getnet %s", btxt_dialled) #cmd0 | getline netdesttype #close cmd0 #printf("cmd0=[%s]\n", cmd0) #nettype = sprintf("MOBILEONNET_%s", netdesttype) outrec() #printf("\n") next } } function outrec() { printf("%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%d|%0.2f|\n", servicenumber, carrier, callclass, billperiod, sdate_str, btxt_stime_str, btxt_origin, btxt_destination, btxt_dialled, btxt_rate, dursecs, costinclgst) } END { } ' >$outfile test -f callclass.uniq && mv -f callclass.uniq callclass_$1.uniq test -f btxt_dialled.uniq && mv -f btxt_dialled.uniq btxt_dialled_$1.uniq exit 0