rstevens@noao.edu (Rich Stevens) (01/19/91)
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
Dan_Jacobson@ATT.COM (01/20/91)
--text follows this line--
>>>>> On 18 Jan 91 09:22:00 GMT, frechett@spot.Colorado.EDU (-=Runaway Daemon=-) said:
frec> In perl, I broke it up into r and oadkill and then did a
frec> y/a-z/A-Z on the r part and then stuck it back together. I
frec> can't find anything that will do that in awk..
Try sed, Fred. Sed has that y/// command too.
[you'll have to muck about with the "hold space" etc. though.]
--
Dan_Jacobson@ATT.COM Naperville IL USA +1 708-979-6364