#! /bin/sh #-rw-rw-rw- 1 root sys 2989083 Jun 12 13:27 mobconf_2014.csv #-rw-rw-rw- 1 root sys 2018941 Jun 12 13:28 mobdata_2014.csv gawk -F',' ' function trim(s) { sub(/^[ \t]*/,"",s) sub(/[ \t]*$/,"",s) return s } function fixforfname(s) { gsub(/\//,"+",s) return s } #month : recordno,mobconf_mobile,sidmainttype,mobconf_sdate,mobconf_edate,directoryID,grid,datatype,serviceproviderdir,carriercode,grname1,grname3,surname,firstname,manufacturer,model,servicetype,dataplan #Apr_2014/mobconf.unl:10000,0401103202,mobile_phones,01/07/2009,,7809,,3,OPTUS,o,OPEN DAY,OPEN DAY,SELVENDRA,ASHA,,,,VND1, function ld_mobconf(mobconffile) { #printf("ld_mobconf(%s)\n", mobconffile) while ( (getline aline < mobconffile) > 0 ) { split(aline, a_arr, ",") #printf("aline=%s\n", aline) f = 0 # from getSIDMAINTconf #recordno = trim(a_arr[++f]) f1 = trim(a_arr[++f]) mobconf_mobile = trim(a_arr[++f]) sidmainttype = trim(a_arr[++f]) mobconf_sdate = trim(a_arr[++f]) mobconf_edate = trim(a_arr[++f]) directoryID = trim(a_arr[++f]) grid = fixforfname(trim(a_arr[++f])) datatype = trim(a_arr[++f]) serviceproviderdir = trim(a_arr[++f]) carriercode = trim(a_arr[++f]) grname1 = trim(a_arr[++f]) grname3 = fixforfname(trim(a_arr[++f])) surname = trim(a_arr[++f]) firstname = trim(a_arr[++f]) manufacturer = trim(a_arr[++f]) model = trim(a_arr[++f]) servicetype = trim(a_arr[++f]) genfld4 = trim(a_arr[++f]) dataplan = genfld4 split(f1, f1_arr, ":") billperiod = substr(f1_arr[1],1,8) recordno = f1_arr[2] atag = billperiod "|" mobconf_mobile billperiod_mobile_to_aline_arr[atag] = aline billperiod_mobile_to_dataplan_arr[atag] = dataplan #print "billperiod_mobile_to_dataplan_arr[" atag "]=[" billperiod_mobile_to_dataplan_arr[atag] "]" } close(mobconffile) } BEGIN { ld_mobconf("mobconf_2014.csv") } { #month : datasrcid,servicenumber,carrier,rectype,recclass,billperiod,sdate_str,btxt_stime_str,btxt_origin,btxt_destination,btxt_dialled,dataKB,rec_count,oldcost,newcost #Apr_2014/TELMAX21/wb2_m11_042014.in:10060,0400004740,OPTUS,CHARGE_DESC,CALL,Apr_2014,,,INTERNETRECALC,Internet Data 1052198Kb, to Apr_2014,1052198,254,0.00000,5.13769, #print $0 f = 0 f1 = trim($(++f)) servicenumber = trim($(++f)) carrier = trim($(++f)) rectype = trim($(++f)) recclass = trim($(++f)) billperiod = trim($(++f)) sdate_str = trim($(++f)) btxt_stime_str = trim($(++f)) btxt_origin = trim($(++f)) btxt_destination = trim($(++f)) btxt_dialled = trim($(++f)) dataKB = trim($(++f)) rec_count = trim($(++f)) oldcost = trim($(++f)) newcost = trim($(++f)) split(f1, f1_arr, ":") billperiod = substr(f1_arr[1],1,8) recordno = f1_arr[2] atag = billperiod "|" servicenumber mobconf_aline = billperiod_mobile_to_aline_arr[atag] mobconf_dataplan = billperiod_mobile_to_dataplan_arr[atag] #print " mobconf_dataplan=[" mobconf_dataplan "]" print $0 mobconf_aline } ' < "mobdata_2014.csv"