#! /bin/sh ifiles="\ ec7_Jan_2014.csv \ ec7_Feb_2014.csv \ ec7_Mar_2014.csv \ " #siteid,calldate,endtime,inlettype,inletno,outlettype,outletno,calltype,calltypedesc,callcategory,dialledno,duration,callcost,expandedcalltype # #101,01/01/2014,000051,B,4000002,E,62046,K,I/C Public,P,00437128981,0,0.0,O #101,01/01/2014,000121,E,63744,K,4000001,M,Mobile Phone,M,00418174218,880,0.11,O #101,01/01/2014,000159,E,66234,L,1000031,a,ISDN LOCAL,L,098090708,48,0.11,O #101,01/01/2014,000213,E,65215,K,4000001,a,ISDN LOCAL,L,098516888,0,0.0,O cat $ifiles | awk -F ',' ' function trim(s) { sub(/^[ \t]*/,"",s) sub(/[ \t]*$/,"",s) gsub(/\,/,";",s) return s } { f = 0 siteid = trim($(++f)) calldate = trim($(++f)) endtime = trim($(++f)) inlettype = trim($(++f)) inletno = trim($(++f)) outlettype = trim($(++f)) outletno = trim($(++f)) calltype = trim($(++f)) calltypedesc = trim($(++f)) callcategory = trim($(++f)) dialledno = trim($(++f)) duration = trim($(++f)) callcost = trim($(++f)) expandedcalltype = trim($(++f)) # skip headers and blank rows if ( siteid == "siteid" || siteid == "" ) next dd = substr(calldate,1,2) mm = substr(calldate,4,2) yyyy = substr(calldate,7,4) month = yyyy "/" mm if ( callcategory == "L" ) { # Local print $0 month_local_count_arr[month] += 1 month_local_cost_arr[month] += callcost } } END{ for ( month in month_local_count_arr ) { print "month Local Count,Cost [" month "]=" month_local_count_arr[month] "," month_local_cost_arr[month] } } '