home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / perl / 7964 < prev    next >
Encoding:
Text File  |  1993-01-23  |  817 b   |  42 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!rpi!utcsri!geac!torag!zooid!stramba
  3. From: Mike Stramba <stramba@zooid.guild.org>
  4. Subject: How to do commas in sed,awk or C
  5. Organization: ZOOiD BBS
  6. Date: Sat, 23 Jan 1993 11:51:42 GMT
  7. Message-ID: <1993Jan23.115142.27369@zooid.guild.org>
  8. Lines: 32
  9.  
  10. From the camel book is the commas routine:
  11.  
  12.  sub commas {
  13.             local($_) = @_;
  14.             1 while s/(.*\d)(\d\d\d)/$1,$2/;
  15.         $_;
  16.  }
  17.  
  18. ----------
  19. How would I do this in sed, awk and C ?
  20.  
  21. For sed, I tried  
  22.  
  23.  sed 's/\(.*[0-9]\)\([0-9][0-9][0-9]\)/\1,\2/g'
  24.  
  25. which only replaced the rightmost 3 digits ... i.e.  3434343433,343.
  26.  
  27. For awk I tried using the 'sub' command with while, but didn't get too far.
  28.  
  29. For C, I'm sure the code I had was far more complicated than need be.
  30.  
  31. Mike
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.