[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Command-line program to convert 'human' sizes?
From: |
Assaf Gordon |
Subject: |
Re: Command-line program to convert 'human' sizes? |
Date: |
Wed, 05 Dec 2012 18:13:12 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:10.0.4) Gecko/20120510 Icedove/10.0.4 |
Hello,
Attached is a working version of numfmt.
The following are implemented:
===
Usage: ./src/numfmt [OPTIONS] [NUMBER]
Reformats NUMBER(s) to/from human-readable values.
Numbers can be processed either from stdin or command arguments.
--from=UNIT Auto-scale input numbers to UNITs. Default is 'none'.
See UNIT below.
--from-unit=N Specify the input unit size (instead of the default 1).
--to=UNIT Auto-scale output numbers to UNITs.
See UNIT below.
--to-unit=N Specify the output unit size (instead of the default 1).
--round=METHOD Round input numbers. METHOD can be:
ceiling (the default), floor, nearest
--suffix=SUFFIX Add SUFFIX to output numbers, and accept optional SUFFIX
in input numbers.
--padding=N Pad the output to N characters.
Default is right-aligned. Negative N will left-align.
Note: if N is too small, the output will be truncated,
and a warning will be printed to stderr.
--grouping Group digits together (e.g. 1,000,000).
Uses the locale-defined grouping (i.e. have no effect
in C/POSIX locales).
--field N Replace the number in input field N (default is 1)
-d, --delimiter=X use X instead of whitespace for field delimiter
===
Also included in the patch is a test file, testing all sorts of combination of
the parameters (hopefully catches most of the corner cases).
There's also an undocumented option "--debug" that will show what's going on:
===
$ /src/numfmt --debug --field 2 --suffix=Foo --from=SI --to=IEC "Hello 70MFoo
World"
Extracting Fields:
input: 'Hello 70MFoo World'
field: 2
prefix: 'Hello'
number: '70MFoo'
suffix: 'World'
Trimming suffix 'Foo'
Parsing number:
input string: '70M'
remaining characters: ''
numeric value: 70000000
Formatting output:
value: 70000000
humanized: '67M'
Hello 67MFoo World
===
Comments are welcomed,
-gordon
numfmt3.patch.gz
Description: GNU Zip compressed data
- Re: Command-line program to convert 'human' sizes?, (continued)
- Re: Command-line program to convert 'human' sizes?, Pádraig Brady, 2012/12/04
- Re: Command-line program to convert 'human' sizes?, Assaf Gordon, 2012/12/04
- Re: Command-line program to convert 'human' sizes?, Assaf Gordon, 2012/12/04
- Re: Command-line program to convert 'human' sizes?, Pádraig Brady, 2012/12/04
- Re: Command-line program to convert 'human' sizes?, Assaf Gordon, 2012/12/04
- Re: Command-line program to convert 'human' sizes?, Pádraig Brady, 2012/12/04
- Re: Command-line program to convert 'human' sizes?, Jim Meyering, 2012/12/04
- Re: Command-line program to convert 'human' sizes?, Pádraig Brady, 2012/12/04
- Re: Command-line program to convert 'human' sizes?, Assaf Gordon, 2012/12/04
- Re: Command-line program to convert 'human' sizes?, Pádraig Brady, 2012/12/04
- Re: Command-line program to convert 'human' sizes?,
Assaf Gordon <=
- Re: Command-line program to convert 'human' sizes?, Assaf Gordon, 2012/12/05
- Re: Command-line program to convert 'human' sizes?, Jim Meyering, 2012/12/05
- Re: Command-line program to convert 'human' sizes?, Assaf Gordon, 2012/12/05
- Re: Command-line program to convert 'human' sizes?, Assaf Gordon, 2012/12/05
- Re: Command-line program to convert 'human' sizes?, Assaf Gordon, 2012/12/05
- Re: Command-line program to convert 'human' sizes?, Pádraig Brady, 2012/12/06
- Re: Command-line program to convert 'human' sizes?, Bernhard Voelker, 2012/12/06
- Re: Command-line program to convert 'human' sizes?, Pádraig Brady, 2012/12/06
- Re: Command-line program to convert 'human' sizes?, Bernhard Voelker, 2012/12/07
- Re: Command-line program to convert 'human' sizes?, Pádraig Brady, 2012/12/07