Setting my prompt

Rich Stevens rstevens at noao.edu
Sat Jan 19 16:51:36 AEST 1991


Case conversion in awk is hard.  Bentley & Kernighan finish their
paper "Tools for Printing Indixes" with the comment: "there is no
good way to convert cases in awk."  The actual code that they
use in this paper to convert case is:

 BEGIN {	FS = "\t"
 	s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz "
 	# set upper["a"] = "A"
 	for (i = 1; i <= 27; i++) upper[substr(s,i+27,1)] = substr(s,i,1)
 	# set lower["a"] =  lower["A"] ="a"
 	for (i = 1; i <= 27; i++) {
 		lower[substr(s,i,1)] = substr(s,i+27,1)
 		lower[substr(s,i+27,1)] = substr(s,i+27,1)
 	}
 }

(Ugh)  This should work with any version of awk.

But, the newer releases of awk (the "nawk" available from the
Toolchest) do contain new functions toupper() and tolower().
GNU awk also contains these new functions.  As I recall, only
versions of nawk that were obtained from the Toolchest since
about 11/89 contain these functions.  I see that the version
of nawk with SunOS 4.1 doesn't yet have these functions.
These functions weren't in awk when the book was written by
AK&W, so they're still somewhat unknown.  I wonder if they're
in the new O'Reilly book on awk ?

	Rich Stevens



More information about the Comp.unix.questions mailing list