: !/bin/sh # CentreVRT_15Nov2010.csv #ID,Description,DepartmentID,Department,GroupID,GroupName,CustomerID,ShipTo,FullName,StartDate,EndDate,Active,PERSON #192,165,2900,NOM VOICE AND DATA,1515,TELECOMMUNICATION SERVICES,499,VRT,VRT Victrack,10-05-2005,,TRUE,STEPHEN ROBERTS # table "catcom".wbdconf # recordno integer not null, # distid serial not null, # distiddesc char(40) not null, # lastdist char(8), # lastdistdate date, # altemail char(50), # altemailyn char(1), # wbd_method char(15) not null, # wbd_type char(15) not null, # userid char(25), # passwd char(132), # sdate date not null, # edate date # table "catcom".wbdlist # distid integer not null, # grid char(8) not null wbdconffile="wbdc1.unl" wbdlistfile="wbdl1.unl" rm -f "$wbdconffile" rm -f "$wbdlistfile" awk -F ',' -v "wbdconffile=$wbdconffile" \ -v "wbdlistfile=$wbdlistfile" \ ' function trim(s) { sub(/^[ \t]*/,"",s) sub(/[ \t]*$/,"",s) return s } function ld_tPerson(tPersonfile) { while ( (getline aline < tPersonfile) > 0 ) { split(aline, a_arr, "|") #printf("aline=%s\n", aline) f = 0 PersonID = trim(a_arr[++f]) Person = toupper(trim(a_arr[++f])) StartDate = trim(a_arr[++f]) EndDate = trim(a_arr[++f]) Active = trim(a_arr[++f]) emailaddress = trim(a_arr[++f]) Person_to_ID_arr[Person] = PersonID PersonID_to_email_arr[PersonID] = emailaddress #print "ld_tPerson() Person_to_ID_arr[" Person "]=[" Person_to_ID_arr[Person] "]" } close(tPersonfile) } BEGIN{ ld_tPerson("tPerson.unl") nextdistid = 2001 } { # print $0 if ( NR == 1 ) # skip header next f = 0 ID = trim($(++f)) Description = trim($(++f)) DepartmentID = trim($(++f)) Department = trim($(++f)) GroupID = trim($(++f)) GroupName = trim($(++f)) CustomerID = trim($(++f)) ShipTo = trim($(++f)) FullName = trim($(++f)) StartDate = trim($(++f)) EndDate = trim($(++f)) Active = trim($(++f)) Person = trim($(++f)) PersonID = Person_to_ID_arr[Person] if ( PersonID == "" ) { print "Error: Person [" Person "] not found in tPerson" next } email = PersonID_to_email_arr[PersonID] if ( email == "" ) { print "Error: Person [" Person "] ID [" PersonID "] has no email address" next } print "mkwbd1: Person [" Person "] ID [" PersonID "] EmailAddress [" email "]" thisdistid = PersonID_to_distid_arr[PersonID] if ( PersonID_to_distid_arr[PersonID] == "" ) { # create new distid #thisdistid = PersonID thisdistid = nextdistid++ } else { print "Warning: Person [" Person "] ID [" PersonID "] has more than one Department" } if ( done_distid_wbdconf_arr[thisdistid] == "" ) { # create wbdconf entry recordno = PersonID distid = thisdistid distiddesc = "Bilmax21 distribution List for " Person lastdist = "" lastdistdate = "" altemail = "" altemailyn = "N" wbd_method = "WEB" wbd_type = "STANDARD" userid = "use_email" passwd = "0x101e1ff4262e2147" # (bilmax21) sdate = StartDate edate = "" print recordno "|" distid "|" distiddesc "|" lastdist "|" lastdistdate "|" altemail "|" altemailyn "|" wbd_method "|" wbd_type "|" userid "|" passwd "|" sdate "|" edate "|" >> wbdconffile done_distid_wbdconf_arr[thisdistid] = "1" } # create wbdlist entry1 distid = thisdistid grid = "DEPT" DepartmentID print distid "|" grid "|" >> wbdlistfile } ' < CentreVRT_15Nov2010.csv >$0.out grep "Error:" $0.out >$0.err grep "Warning:" $0.out >$0.warn exit 0