[Top][All Lists]

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

RFC: add'l 'sort -n' options

From: Matthew Woehlke
Subject: RFC: add'l 'sort -n' options
Date: Fri, 03 Nov 2006 09:55:25 -0600
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20060909 Thunderbird/ Mnenhy/

I was thinking about some additional ways 'sort -n' might work. I'm not asking for someone to do these (I was thinking about doing some myself); just looking for comment on what other people think about the possibility.

The new option would be:
'-N _options_, --numeric-sort=_options_'
...and would imply '-n'.

(note that means an overload of '--numeric-sort', i.e. without the '=' would just be '-n' as it is now).

_options_ would be one or more letters:

'f': equivalent to '-g/--general-numeric-sort', i.e. convert numbers with strtod.

'a': convert numbers with strtol(,0) (i.e. automatically recognize '0x<num>' (hex), '0<num>' (octal).

'o': all numbers are octal, i.e. strtol(,8)

'x': all numbers are hexadecimal, i.e. strtol(,16)

'r': recursive; when comparing two strings, discard leading matches and then compare according to numeric rules. This would allow correct sorting of e.g. 'x.y.z-pl' (version/patch level), 'yyyy.mm.dd' (dates, where the '.' can be any separator), etc. Possible candidate for '-R' and long-opt.

'h': numbers are 'human-readable', i.e. '<num>[kK]
is 1024*<num>, similar with [mM], [gG], [tT]. Possible candidate for '-H'/'-h' and long-opt.

'd': use 1000 instead of 1024 for 'h' (above).

'f', 'x', 'o', 'a' are mutually exclusive.

...and in light of 'o', 'x', perhaps '-B <num>, --numeric-base <num>' would be in order?

I'm very open to suggestion on this; the objectives are a: to parse 'du -h' output, and b: to implement the functionality of 'r'. I'm not particularly attached to any specific means of achieving this.

"I don't question your existence -- God" (seen on a church billboard)

reply via email to

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