Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!spool2.mu.edu!sdd.hp.com!usc!julius.cs.uiuc.edu!psuvax1!rutgers!noao!rstevens From: rstevens@noao.edu (Rich Stevens) Newsgroups: comp.unix.questions Subject: Re: Setting my prompt Summary: case conversion in awk Message-ID: <1991Jan19.055136.20816@noao.edu> Date: 19 Jan 91 05:51:36 GMT References: <1991Jan18.092200.6009@csn.org> Organization: National Optical Astronomy Observatories, Tucson AZ Lines: 29 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