coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding humanize_number to coreutiles?


From: Pádraig Brady
Subject: Re: Adding humanize_number to coreutiles?
Date: Tue, 14 Feb 2012 13:30:40 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:6.0) Gecko/20110816 Thunderbird/6.0

On 02/14/2012 12:59 PM, Jim Meyering wrote:
> Pádraig Brady wrote:
> ...
>> Looking more at this, you might be right.
>> Now printf already has related formatting functionality:
>>
>> $ env LANG=fa_IR.utf8 printf "%I'd\n" 1234
>> ۱٬۲۳۴
>>
>> I was thinking it would be appropriate to add "human" into the mix like
>>
>> $ env LANG=fa_IR.utf8 printf "%Hd\n" 1234
>> 1K
>>
>> $ env LANG=fa_IR.utf8 printf "%HId\n" 1234
>> ۱K
>>
>> But as you say there are options for humanizing.
>> So would there be enough cohesive functionality one could add to such a util?
>> I suppose so, since one could add field processing and
>> multiplier support for example.
>>
>> Also what to call it? humanize_number is too long I think.
>> Perhaps we could use a more general name. Drats I was
>> thinking of `numconv`, but that's taken:
>> http://www.unixref.com/manPages/numconv.html
>> Maybe `convnum`, anyway...
> 
> human-readable   too long and hyphenated
> hr               short, but in the unix tradition (like od, dd, etc.)

Hmm, well "humanize" might be a bit of an amorphous term
to have as the base verb for the command.
Perhaps adding a --human option is clear enough,
since it would not be the only mode of operation.
I.E. support `convnum -h`, where:

  -h, --human  Same as --to=SI

I'm not that happy with convnum though.
What about `numfmt`. Shorter than convnum,
we already have `fmt`, and the util presented
has a central --format option.
So what I have so far is:


numfmt [OPTIONS] [NUMBER]...

Reformat NUMBER(s)
Numbers can be processed either from stdin or command arguments

--from={auto,SI,IEC}
If not specified, suffixes are ignored
auto => 1K -> 1000, 1Ki -> 1024
SI => 1K* -> 1000
IEC => 1K* -> 1024

--from-unit=<NUMBER>
Specify the unit size.
--from-unit=1 is implied if not specified

--to={SI,IEC,<NUMBER>}
Auto scale the numbers to SI (powers of 1000),
or IEC (powers of 1024), so at most 3 digits are output.
Note output will be standard, without a B suffix.
I.E. 123K or 123Ki for SI and IEC respectively.
If <NUMBER> is specified use this as the scale.

--to-unit=<NUMBER>
Specify the output unit size.
--to-unit=1 is implied if not specified

--round={ceiling, floor, nearest}
--round=ceiling is implied if not specified

-f, --format=FORMAT
--format=%d is implied if not specified
You can use this to specify a space after the number
You can also use this to perform grouping (with %'d)
You can also use this to select alternative number forms (with %Id) etc.

--suffix=SUFFIX
Example --suffix=B

--field=NUM
replace the number in the portion of the line delimited by whitespace.
If the new number is narrower, then pad to the same field width with spaces.

<NUMBER>s specified above can be numeric
with an optional suffix, like K, Ki.
(Note K should probably be SI here, unlike other coreutils).

cheers,
Pádraig.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]