Neophyte awk question(s)

Henry Spencer henry at utzoo.UUCP
Wed Sep 26 04:07:37 AEST 1984


> 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



More information about the Comp.unix mailing list