Xref: utzoo comp.lang.c:24762 comp.unix.xenix:9232 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!rutgers!cmcl2!phri!cooper!dasys1!jpr From: jpr@dasys1.UUCP (Jean-Pierre Radley) Newsgroups: comp.lang.c,comp.unix.xenix Subject: Re: printf format Keywords: comma.sed Message-ID: <11443@dasys1.UUCP> Date: 24 Dec 89 01:02:03 GMT References: <5761@ozdaltx.UUCP> Reply-To: jpr@dasys1.UUCP (Jean-Pierre Radley) Organization: TANGENT Lines: 28 In article <5761@ozdaltx.UUCP> root@ozdaltx.UUCP (root) writes: >In the back of my mind, it seems like I read that there is a format >character used in printf(C) that allows the formatting of numbers. >I'd like to take a number, ie. 123456.78 and print it as >123,456.78 . >If printf does not have this ability, it should be added. And make allowances for European conventions too, eh? In the meantime, while working on a General Ledger program which used 'awk' for formatting, I found the same limitation in the 'printf' function of 'awk'. So I wrote a sed filter to insert my commas: sed -f comma.sed outfile where comma.sed is: # comma.sed, inserts commas in numbers preceded by enough blanks : R /[0-9][0-9][0-9[0-9][,.]/s/ \([-+0-9]*[0-9]\)\([0-9][0-9][0-9][,.]\)/\1,\2/g t R I noted, along the way, that a sed script allows ONE commented line at the outset. -- Jean-Pierre Radley jpr@jpradley.uucp New York, NY 72160.1341@compuserve.com