home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / alt / lang / awk / 10 next >
Encoding:
Text File  |  1993-01-21  |  1.8 KB  |  68 lines

  1. Newsgroups: alt.lang.awk
  2. Path: sparky!uunet!cs.utexas.edu!geraldo.cc.utexas.edu!portal.austin.ibm.com!awdprime.austin.ibm.com!tbates
  3. From: tbates@austin.ibm.com ()
  4. Subject: Re: tolower() function?
  5. Originator: tbates@rama.austin.ibm.com
  6. Sender: news@austin.ibm.com (News id)
  7. Message-ID: <C184vr.p5q@austin.ibm.com>
  8. Date: Thu, 21 Jan 1993 21:55:03 GMT
  9. References: <1993Jan19.152725.3510@trentu.ca> <EMCOOP.93Jan19111755@bcars148.bnr.ca>
  10. Organization: IBM Austin
  11. Lines: 55
  12.  
  13.  
  14. In article <EMCOOP.93Jan19111755@bcars148.bnr.ca>, emcoop@bnr.ca (hume smith) writes:
  15. > In article <1993Jan19.152725.3510@trentu.ca> ccgwt@trentu.ca (Grant Totten) writes:
  16. >    Is there a 'covert the line to lower case' function available in awk?
  17. >    Or even 'convert to lower case except for the first character of the
  18. >    line' function?
  19. > gawk has tolower
  20. > --
  21. > Hume Smith                                    My name is little Bongo
  22. > hume.smith@acadiau.ca                         I sing my little song-go
  23. > emcoop@bnr.ca                                 Rhymes are hard to think of
  24. >                                               Except for made-up words like "flong-go"
  25.  
  26. Quoting "The AWK Programming Language",
  27.  
  28.     "The cleanest way to do case conversion in awk is with an array that
  29. maps each letter...it's better to use...tr"
  30.  
  31. I often use tr for this very reason. For example:
  32.  
  33.     echo "HeLlO, wOrLd!" | tr [:upper:] [:lower]
  34.  
  35. This gives you:
  36.  
  37.     hello, world!
  38.  
  39. To use tr from awk:
  40.  
  41. #!/bin/awk -f
  42.    {
  43.    "echo "$0" | tr [:upper:] [:lower:]" | getline
  44.    print
  45. }
  46.  
  47. To skip the first character:
  48.  
  49. #!/bin/awk -f
  50.    {
  51.    start_of_line=$0
  52.    rest_of_line=$0
  53.    start_of_line=substr($0,1,1)
  54.    rest_of_line=substr($0,2)
  55.    "echo " rest_of_line " | tr [:upper:] [:lower:]" | getline rest_of_line
  56.    print start_of_line rest_of_line
  57. }
  58.  
  59.     Sincerely,
  60.         Tom
  61. -- 
  62. Tom Bates
  63.  
  64. IBM Austin
  65.  
  66.