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

Re: sort (-g) [offtopic]



On Tue 27 Feb 2018 at 09:48:57 (+0100), Ionel Mugurel Ciobîcă wrote:
> On 19-02-2018, at 03h 23'27", Will Mengarini wrote about "Re: sort (-g) [offtopic]"
> > * Ionel Mugurel Ciobica <I.M.Ciobica@upcmail.nl> [18-02/18=Su 16:55 +0100]:
> > > [... How can something like
> > > "III\nII\nI\nV\nIV\nVII\nVI\nVIII\nX\nIX"
> > > [be sorted?  ...]
> > 
> > See `aptitude show msort`; it probably does what you need.
> 
> 
> I can't see how that would work, I have read the manual and tried
> almost all options. At best msort is still behaves as sort, placing IX
> in between IV and V:
> 
> # cat roman
> X
> III
> II
> XI
> IV
> V
> VI
> VIII
> VII
> IX
> XII
> I
> 
> # cat roman | msort -q -w -l -y ROMAN
> I
> II
> III
> IV
> IX
> V
> VI
> VII
> VIII
> X
> XI
> XII
> 
> # cat roman | sort 
> I
> II
> III
> IV
> IX
> V
> VI
> VII
> VIII
> X
> XI
> XII
> 
> Did I miss anything?

Yes, you need to read §3.4.2.8 over again:

"If the argument to the -c option begins with m or M msort will treat
the key as the name of a month. If the -s option is also used with
this key and its argument is the name of a file, month names will be
read from the file. The file should have the same format as a sort
order specification file. All entries on the same line will be given
the same sort rank. The sort rank will follow the order of the
lines. This approach permits the use of calendars with more than
twelve months. It also allows multiple abbreviations or names for the
same month."

IOW you should write a file containing

I i
II ii
etc.

and feed it to -s.

> Besides, how this msort will work in a pipe, when I have to sort by
> date, things like 3-V-2017 and 17-IX-2016, I can't find the equivalent
> of -k from sort into this msort.
> 
> What I need is something like sort -t- -k3,3n -k2,2m -k1,1n, where m
> would ideally be the sorting of Roman numerals (or the months as Roman
> numerals)...
> 
> Is there a way to add this extension to sort? Like it is right now:
> 
> | --sort=WORD
> |               sort according to WORD: general-numeric -g,
> | human-numeric -h, month -M, numeric -n, random -R, version -V
> 
> to add "roman numerals -m"
> and to be able to specify a file with (all) roman numerals in their
> proper order and ask sort to order using that 'dictionary'?

Precisely the method that I've quoted above.

> I am willing to try to add this to sort if anyone can point me in the
> right direction...

Cheers,
David.


Reply to: