printf format
Jean-Pierre Radley
jpr at dasys1.UUCP
Sun Dec 24 12:02:03 AEST 1989
In article <5761 at ozdaltx.UUCP> root at 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 <infile >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 at jpradley.uucp
New York, NY 72160.1341 at compuserve.com
More information about the Comp.lang.c
mailing list