Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: Separating big numbers with commas

by Anonymous Monk
on Dec 15, 2018 at 22:39 UTC ( #1227307=note: print w/replies, xml ) Need Help??


in reply to Re^2: Separating big numbers with commas
in thread Separating big numbers with commas

I'm not a ksh user, but this script seems to work for me.

===

cat ~/.local/bin/commafy #!/usr/bin/perl -nl $_ =~ s/(\d)(?=(\d{3})+(\D|$))/$1\,/g; print;

===

My usage (to find out that a recent nix build used 18 GB of space):

$ find /nix/store -cmin -150 | perl -nle '$sum+=-s "$_";END{print $sum +}' | commafy 18,025,136,505

2018-12-16 Athanasius added code and paragraph tags

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1227307]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2021-06-24 13:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (128 votes). Check out past polls.

    Notices?