home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!rpi!utcsri!geac!torag!zooid!stramba
- From: Mike Stramba <stramba@zooid.guild.org>
- Subject: How to do commas in sed,awk or C
- Organization: ZOOiD BBS
- Date: Sat, 23 Jan 1993 11:51:42 GMT
- Message-ID: <1993Jan23.115142.27369@zooid.guild.org>
- Lines: 32
-
- From the camel book is the commas routine:
-
- sub commas {
- local($_) = @_;
- 1 while s/(.*\d)(\d\d\d)/$1,$2/;
- $_;
- }
-
- ----------
- How would I do this in sed, awk and C ?
-
- For sed, I tried
-
- sed 's/\(.*[0-9]\)\([0-9][0-9][0-9]\)/\1,\2/g'
-
- which only replaced the rightmost 3 digits ... i.e. 3434343433,343.
-
- For awk I tried using the 'sub' command with while, but didn't get too far.
-
- For C, I'm sure the code I had was far more complicated than need be.
-
- Mike
-
-
-
-
-
-
-
-
-
-
-