#! /bin/sh awk -F "," ' function trim(s) { sub(/^[ \t]*/,"",s) sub(/[ \t]*$/,"",s) gsub(/\"/,"",s) return s } function ld_defdp(defdpfile) { #printf("ld_defdp(%s)\n", defdpfile) while ( (getline aline < defdpfile) > 0 ) { split(aline, a_arr, "|") #printf("aline=%s\n", aline) #32767|000|Emergency|T|N|f| f = 0 siteid = trim(a_arr[++f]) prefix = trim(a_arr[++f]) desc = trim(a_arr[++f]) pulsetype = trim(a_arr[++f]) chcode = trim(a_arr[++f]) calltype = trim(a_arr[++f]) defdpdesc_to_prefix_arr[desc] = prefix #print "defdpdesc_to_prefix_arr[" desc "] = [" defdpdesc_to_prefix_arr[desc] "]" } close(defdpfile) } BEGIN { ld_defdp("defdp") } { #siteid,prefix,destination,pulsetype,chcode,calltype, if ( NR == 1 ) { # header print $0 next } f = 0 siteid = trim($(++f)) prefix = trim($(++f)) destination = trim($(++f)) pulsetype = trim($(++f)) chcode = trim($(++f)) calltype = trim($(++f)) # skip if dest not in defdp if ( defdpdesc_to_prefix_arr[destination] != "" ) { #print "SKIP: " $0 next } print $0 } '