Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!henry From: henry@utzoo.UUCP (Henry Spencer) Newsgroups: net.unix Subject: Re: Neophyte awk question(s) Message-ID: <4363@utzoo.UUCP> Date: Tue, 25-Sep-84 14:07:37 EDT Article-I.D.: utzoo.4363 Posted: Tue Sep 25 14:07:37 1984 Date-Received: Tue, 25-Sep-84 14:07:37 EDT References: <487@loral.UUCP> Organization: U of Toronto Zoology Lines: 31 > I needed an awk process to output an SOH character (binary 1). When > I put the following in: > > {printf"%c",'\001'} > > awk complained and stubbornly refused. However, the exact same > thing in C (given the syntactical difference with parentheses) > works fine. I understood that the 'printf' statement in awk > was the same as in C. At any rate, I can't seem to get an SOH from > awk. Awk is not C, despite surface similarities and occasional rash statements in the manual. There are no single characters in awk, just strings, so the single quotes are a no-no and the %c format is meaningless. More serious, alas, is that awk takes "\001" as a string four characters long, so there isn't any good answer to your problem. > Also, I needed to do a lower-to-upper case conversion. All the mathematical > tricks failed and I wound up creating a string of the alphabet in > upper, then lower case and using 'index' and 'substr' functions > to do it. Is there a better way? The right way to do this in C is to avoid the slightly-unportable mathematical tricks and use toupper() and tolower(); alas, awk doesn't seem to have them. The mathematical tricks don't work because awk does not have C's tolerance for type punning, e.g. treating a character as an integer. I think the way you did it is the best available. -- Henry Spencer @ U of Toronto Zoology {allegra,ihnp4,linus,decvax}!utzoo!henry