home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / unix / shell / 4554 < prev    next >
Encoding:
Internet Message Format  |  1992-11-06  |  1.9 KB

  1. Xref: sparky comp.unix.shell:4554 comp.lang.misc:3509
  2. Newsgroups: comp.unix.shell,comp.lang.misc
  3. Path: sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!elroy.jpl.nasa.gov!sdd.hp.com!sgiblab!munnari.oz.au!cs.mu.OZ.AU!minh
  4. From: minh@lis.rch.unimelb.edu.au (Minh Tran)
  5. Subject: Re: Need script (awk/sed/...) to remove dashes and do initial caps
  6. Message-ID: <9231112.13182@mulga.cs.mu.OZ.AU>
  7. Sender: news@cs.mu.OZ.AU
  8. Organization: Computer Science, University of Melbourne, Australia
  9. X-Newsreader: TIN [version 1.1 PL6]
  10. References: <Bx5t40.5DB@unx.sas.com>
  11. Date: Fri, 6 Nov 1992 01:17:31 GMT
  12. Lines: 46
  13.  
  14. Mark Burhans (sasmob@chewy.unx.sas.com) wrote:
  15. >   Here is an awk script that seems to work for me:
  16. > ----Cut Here----
  17. > {
  18. >     for( f=1; f<=NF; f++ )
  19. >     {
  20. >         # 1.  Make first character Upper Case.
  21. >         # 2.  Make rest of the word Lower Case.
  22. >         sub( substr($f,1,1), toupper( substr( $f, 1, 1)), $f );
  23. >         sub( substr($f,2), tolower( substr($f,2)), $f );
  24. >         # If a '-' is found, get rid of it and make the next
  25. >         # character Upper Case.
  26. >         while( (i=index( $f, "-" )) != 0 )
  27. >         {
  28. >             pattern = substr( $f, i, 2 );
  29. >             sub( pattern, toupper(substr($f,i+1,1)), $f);
  30. >         }
  31. >         # Output what you have.
  32. >         print $f
  33. >     }
  34. > }
  35. > ----Cut Here----
  36.     
  37.     This should work as well ...
  38.  
  39. {
  40.     split($1, parts, "-") ;
  41.     printf("%s%s", toupper(substr(parts[1],1,1)), tolower(substr(parts[1],2)));
  42.     printf("%s%s\n", toupper(substr(parts[2],1,1)), tolower(substr(parts[2],2))) }
  43.  
  44.     ---
  45.     minh
  46.  
  47. --
  48. |>    B\iochemistry                        Minh Tra/N                       <|
  49. |>     I\nformation     minh@lis.rch.unimelb.edu.a/U                        <|
  50. |>      S\ervice                     (03) 345-590/8                         <|
  51. |>       D\epartment         Melbourne, Australi/A                          <|
  52.