On Fri, 31 Mar 2017, Rich Shepard wrote: > Are there available repositories of working, complex awk scripts > for manipulating large text files? These are not related to system > or network administration, but general business information.
Below my .sig is the only mildly complex awk script I've written. The input was a CSV file that had been exported from Excel and run through dos2unix; the invocation was gawk -f myprog.awk -F, datafile.csv > myout.ics FWIW. -- Paul Heinlein <> heinl...@madboa.com <> http://www.madboa.com/ #!/usr/bin/awk # # transform CSV file of company contacts into vCard 3.0 format # # this recipe assumes a certain field order: last name, first name, # home phone, cell phone, galois phone, galois email, alt. email. # # note also the system() call toward the end. it relies on a # GNU-specific option to the date utility. # # ====================================================================== { print "BEGIN:VCARD" print "VERSION:3.0" # everyone should have a first and last name field, so no need to # test for them print "N:"$1";"$2";;;" print "FN:"$2" "$1 # oh, and we all work at MyCorp :-) print "ORG:MyCorp" # print any phone field if it contains digits; a null field might # be empty or it might have the string 'n/a' if ($3 ~ /[0-9]/) print "TEL;TYPE=HOME,VOICE:"$3 if ($4 ~ /[0-9]/) print "TEL;TYPE=CELL,VOICE:"$4 if ($5 ~ /[0-9]/) print "TEL;TYPE=WORK,VOICE:"$5 # print either e-mail field if it contains an '@' character if ($6 ~ /@/) print "EMAIL;type=INTERNET,WORK:"$6 if ($7 ~ /@/) print "EMAIL;type=INTERNET,HOME:"$7 # use printf to avoid getting a newline before the date printf "REV:" # the --iso-8601 option is specific to GNU date, which on a Mac # is installed as 'gdate' (via MacPorts). use plain old 'date' on # a linux machine (which probably has GNU utilities). system("gdate --iso-8601=seconds") print "END:VCARD" } # # eof # _______________________________________________ PLUG mailing list PLUG@lists.pdxlinux.org http://lists.pdxlinux.org/mailman/listinfo/plug