home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!UB.com!pacbell.com!sgiblab!spool.mu.edu!yale.edu!ira.uka.de!rz.uni-karlsruhe.de!fg70.rz.uni-karlsruhe.de!ig25
- From: ig25@fg70.rz.uni-karlsruhe.de (Thomas Koenig)
- Newsgroups: alt.lang.awk
- Subject: Re: tolower() function?
- Date: 28 Jan 93 13:16:55 GMT
- Organization: University of Karlsruhe, Germany
- Lines: 60
- Message-ID: <ig25.728227015@fg70>
- References: <1993Jan19.152725.3510@trentu.ca> <EMCOOP.93Jan19111755@bcars148.bnr.ca> <C184vr.p5q@austin.ibm.com>
- NNTP-Posting-Host: fg70.rz.uni-karlsruhe.de
-
- tbates@austin.ibm.com () writes:
-
-
- >Quoting "The AWK Programming Language",
-
- > "The cleanest way to do case conversion in awk is with an array that
- >maps each letter...it's better to use...tr"
-
- It certainly is cleaner, but not every system which has awk also has
- tr.
-
- For the heck of it, I timed converting a 200 K text file to all upper
- with an awk - script with self - written toup - function,and tr, on a HP
- 9000/720 (not exactly a slow machine :-)
-
- Here are the results:
-
- $ time tr [[:lower:]] [[:upper:]] < faq.linux >/dev/null
-
- real 0m0.33s
- user 0m0.16s
- sys 0m0.07s
-
- $ time toupper < faq.linux >/dev/null
-
- real 0m33.32s
- user 0m32.12s
- sys 0m0.07s
-
- $ cat toupper
- #! /usr/bin/awk -f
- BEGIN {
- a="abcdefghijklmnopqrstuvwxyz"; b="ABCDEFGHIJKLMNOPQRSTUWVXYZ"
- for (i=1; i<=length(a); i++)
- touptab[substr(a,i,1)] = substr(b,i,1)
- }
- { print toup($0) }
- function toup(a ,i ,ch ,res)
- {
- res = ""
- for (i=1; i<=length(a); i++)
- {
- ch = substr(a,i,1)
- if (ch in touptab)
- res = res touptab[ch]
- else
- res = res ch
- }
- return res
- }
-
- Which again shows... leave the stuff which can be handeled by more
- specialized utilities to these, and only use awk when you really need
- it.
-
- Regards
- --
- Thomas Koenig, ig25@rz.uni-karlsruhe.de, ig25@dkauni2.bitnet
- The joy of engineering is to find a straight line on a double
- logarithmic diagram.
-