#!/bin/awk -f # # This should be able to handle: # # Problem records will be output at the end preceeded by BAD and # followed by a rule description of where the problem occured # for easier debugging. # # This was developed on linux, you might want to try nawk or # gawk if you try to use this on Solaris. # # Comments should be stripped before running this program (I didn't # feel like reliably dealing with them yet). Try something like: # sed '-ed/#.*$//' to strip them. # #/^[ ]*#/ { print ; next } # leave comment lines intact { isalias=0 ; RULE=""; DEB="" ALIAS=""; FIRST=""; LAST="" ; EMAIL="" } /^[ ]*alias/ { isalias=1; } # leave non alias lines intact !isalias { next; print ; next } # leave non alias lines intact { ALIAS = $2 } NF==3 { EMAIL = $3 ; RULE=RULE " =3" } NF>3 { if ($NF ~/^<.*>$/) { RULE=RULE " " EMAIL = substr($NF,2,length($NF)-2) sub(/^\\/,"", $3) sub(/^\"/,"", $3) sub(/\"$/,"", $(NF-1)) sub(/\\$/,"", $(NF-1)) if ($3 ~ /,$/) { RULE=RULE " L,F" LAST = $3 for(i=4; i < NF ; i++) FIRST= FIRST " " $i }else{ RULE=RULE " FL" for(i=3; i < NF-1 ; i++) FIRST= FIRST " " $i LAST = $(NF-1) } }else if ($4 ~ /^\(/) { RULE=RULE " 4(" EMAIL = $3 #EMAIL = "<"$3">" if ($NF ~ /\)$/) { RULE=RULE ")" $4 = substr($4, 2) $NF = substr($NF, 1, length($NF)-1) if ($4 ~ /,$/) { RULE=RULE " L,F" LAST = $4 for(i=5; i <= NF ; i++) FIRST= FIRST " " $i }else{ RULE=RULE " FL" for(i=4; i < NF ; i++) FIRST= FIRST " " $i LAST = $NF } } else RULE = RULE " # no end ) " $NF } } #{ sub(/,$/,"", FIRST); sub(/,$/,"", LAST); } { gsub(/,/," ", FIRST); gsub(/,/," ", LAST); } # elminate all commas to not confuse CSV { sub(/ *$/,"", FIRST); sub(/ *$/,"", LAST); } { sub(/^ */,"", FIRST); sub(/^ */,"", LAST); } { FULL = FIRST " " LAST } #!DEB {next} #RULE!="" && RULE !~ /#/ { print EMAIL "," FIRST "," LAST "," ALIAS " RULE:" RULE } RULE!="" && RULE !~ /#/ { print ALIAS "," FIRST "," LAST "," EMAIL } #RULE!="" && RULE !~ /#/ { print ALIAS "," FULL "," FIRST "," LAST "," EMAIL } RULE=="" || RULE ~ /#/ { bad++; BAD[bad] = $0 ; BRULE[bad]=RULE} END { print ; for(i=1 ; i <= bad; i++) print "BAD: " BAD[i] " RULE:"BRULE[i] }