On 05/19/2014 07:41 PM, Carl Ponder wrote:
>
> (This is a feature request, not a bug report, but I couldn't figure out from
> your website info where else to send it).
> I want to use "sort" to order information in the following format
>
> 15us
> 9ms
> 10s
>
> I know that the--human-numeric-sort is able to manage file size units (K, G),
> but it looks like it is not aware of time units (s, ms, us).
> Is this something you can add?
> I'm using the sort version 8.13 (on Ubuntu 12.04), do you already have this
> in a more current version?
> I don't see it in your list of rejected requests (!) so I figure there's a
> chance....
Well this is nothing to do with time, rather supporting fractional SI prefixes:
'm' for milli, 'u' for micro, 'n' for nano etc.
The nice thing is that we wouldn't have to add any new interface to support
this,
and the attached trivial patch would work in this and many cases,
because 's' doesn't overlap with any of the suffixes.
$ printf '%s\n' 10s 15us 9ms 2Gs 8Ms | src/sort -h
15us
9ms
10s
8Ms
2Gs
However note that the --human support in sort is not general and is
only really suitable for sorting the output from a particular
run of du -h or df -h etc. For example the following non normalized
numbers would not sort correctly:
$ printf '%s\n' 12345us 10ms | src/sort -h
12345us
10ms
Given these suffixes would not be generated by coreutils,
and they're very often not normalized so that the suffix
comparison is invalid independently from the number,
we'd have to employ a more general solution I think.
thanks,
Pádraig.
diff --git a/src/sort.c b/src/sort.c
index 3380be6..5fa0a1b 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -1865,24 +1865,33 @@ static char const unit_order[UCHAR_LIM] =
/* This initializer syntax works on all C99 hosts. For now, use
it only on non-ASCII hosts, to ease the pain of porting to
pre-C99 ASCII hosts. */
- ['K']=1, ['M']=2, ['G']=3, ['T']=4, ['P']=5, ['E']=6, ['Z']=7, ['Y']=8,
+ ['m']=-1, ['u']=-2, ['n']=-3, ['p']=-4,
+ ['f']=-5, ['a']=-6, ['z']=-7, ['y']=-8,
['k']=1,
+ ['K']=1, ['M']=2, ['G']=3, ['T']=4,
+ ['P']=5, ['E']=6, ['Z']=7, ['Y']=8,
#else
/* Generate the following table with this command:
- perl -e 'my %a=(k=>1, K=>1, M=>2, G=>3, T=>4, P=>5, E=>6, Z=>7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