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

  1. Xref: sparky comp.unix.shell:4609 comp.lang.misc:3557
  2. Newsgroups: comp.unix.shell,comp.lang.misc
  3. Path: sparky!uunet!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: <9231509.5038@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: <BxB2D1.7yL@unx.sas.com>
  11. Date: Mon, 9 Nov 1992 22:32:39 GMT
  12. Lines: 41
  13.  
  14. Mark Burhans (sasmob@chewy.unx.sas.com) wrote:
  15. > |> {
  16. > |>     split($1, parts, "-") ;
  17. > |>     printf("%s%s", toupper(substr(parts[1],1,1)), tolower(substr(parts[1],2)));
  18. > |>     printf("%s%s\n", toupper(substr(parts[2],1,1)), tolower(substr(parts[2],2))) }
  19. > It works if there is only one word with one "-" in it.  This is neat though.
  20. > That could probably be modified with some effort to handle more than one 
  21. > word per line, and more than one "-".  Some of the LISP I've written and
  22. > seen has variables and procedures with names like:
  23. >   "print-no-of-arguments"  or
  24. >   "get-next-field"
  25. > I messed with this awk for a minute (didn't put much into it) and didn't get
  26. > very far.
  27. > Nice input.
  28.  
  29.     Having got this far the rest is quite easy:
  30.  
  31. {
  32.     for (i = 1; i <= NF; i++)
  33.     {
  34.         n = split($i, part, "-") ;
  35.         for (j = 1; j <= n; j++)
  36.             printf("%s%s", toupper(substr(part[j], 1, 1)), tolower(substr(part[j], 2)));
  37.         printf(" ");  # Just for this example
  38.     }
  39.     printf("\n");
  40. }
  41.  
  42.     Anyway you got the idea.
  43.     ---
  44.     minh
  45.  
  46. --
  47. |>    B\iochemistry                        Minh Tra/N                       <|
  48. |>     I\nformation     minh@lis.rch.unimelb.edu.a/U                        <|
  49. |>      S\ervice                     (03) 345-590/8                         <|
  50. |>       D\epartment         Melbourne, Australi/A                          <|
  51.