: !/bin/sh carrier="VODAFONE" month="$1" infile="$2" #adjmonth=$month #adjmonth=`../../../adjmonth $month` #echo "$0: adjmonth=[$adjmonth]" mm=`echo "$adjmonth" | awk '{ print substr($1,1,2) }'` cc=`echo "$adjmonth" | awk '{ print substr($1,3,2) }'` yy=`echo "$adjmonth" | awk '{ print substr($1,5,2) }'` #echo "$0: mm=[$mm] cc=[$cc] yy=[$yy]" #infile=`ls *${mm}-${yy}-${cc}*.txt` 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 == "263500" ) { if ( linetype == "260500" ) { servicenumber = trim($5) next } ################################################## # rent/call/other (based on TAS vodafone.pas code) # rent if (linetype == "363005" ) { callclass = "" datestr = trim($3) 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($4) 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($5) # description btxt_dialled = from_date " to " to_date dursecs = 0 costinclgst = 0.0 + trim($6) # rent if ( costinclgst != 0 ) { outrec() next } next } ################# # rent if (linetype == "361505" ) { callclass = "" f = 3 datestr = trim($(f++)) 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) if ( NF == 7 ) { datestr = trim($(f++)) 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($(f++)) # description #btxt_dialled = " to " to_date if ( NF == 6 ) btxt_dialled = from_date else btxt_dialled = from_date " to " to_date btxt_rate = "" dursecs = 0 costinclgst = 0.0 + trim($(f++)) # output rent if not 0 if ( costinclgst != 0 ) { outrec() next } } ############### # rent/call/other if (linetype == "361005" ) { 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 == "STDCHG" || linecode == "CREDIT") ) { # btxt_origin = "RENT" # outrec() # next #} # call if ( costinclgst != 0 && (linecode == "USAGE") ) { btxt_origin = "CALL" outrec() next } # other if ( costinclgst != 0 && (linecode == "NSTDCH") ) { btxt_origin = "OTHER" outrec() next } next } ################################################## # call detail if ( linetype == "363505" ) { callclass = trim($4) # Bill Data btxt = $0 #printf("Service Number = [%s] Call Class = [%s]\n", servicenumber, callclass); #printf("%s\n", btxt); datestr = trim($5) yyyy = 0 + substr(datestr,1,4) mm = 0 + substr(datestr,5,2) dd = 0 + substr(datestr,7,2) #printf("yyyy=[%s]\n", yyyy); #printf("dd=[%s] mm=[%s]\n", dd, mm); sdate_str = sprintf("%02d/%02d/%04d", dd, mm, yyyy) stimestr = trim($6) btxt_stime_str = substr(stimestr,1,2) substr(stimestr,3,2) substr(stimestr,5,2) btxt_origin = "" #trim($7) btxt_destination = trim($9) btxt_dialled = trim($8) btxt_duration = trim($11) #printf("btxt_duration=[%s]\n", btxt_duration); durhhh = 0 + substr(btxt_duration,1,3) durmm = 0 + substr(btxt_duration,4,2) durss = 0 + substr(btxt_duration,6,2) #printf("durhhh=[%s] durmm[%s] durss[%s]\n", durhhh, durmm, durss); dursecs = (durhhh * 60 * 60) + (durmm * 60) + durss #printf("dursecs=[%s]\n", dursecs); # see whats in fields #print callclass | "sort -u >callclass.uniq" #print btxt_dialled | "sort -u >btxt_dialled.uniq" #print btxt_duration | "sort -u >btxt_duration.uniq" ### use unprocessed NUMBER for dest description ###btxt_destination = btxt_dialled ## process dialled number to remove inconsistencies #sub(/YES$/, "", btxt_dialled) # remove YES sub(/^\+61/, "0", btxt_dialled) # replace with 0 if ( length(btxt_dialled) >= 13 ) sub(/^0061/, "0", btxt_dialled) # replace with 0 if ( length(btxt_dialled) >= 11 ) sub(/^61/, "0", btxt_dialled) # replace with 0 btxt_rate = trim($10) btxt_cost = trim($14) costinclgst = 0.0 + 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 test -f btxt_duration.uniq && mv -f btxt_duration.uniq btxt_duration_$1.uniq exit 0