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

sort (-g) [offtopic]



Anyone care to explain what exactly means the -g option of sort? The
fine manual only says "general numerical", but I doubt that is true,
because -g (and all other options I have tried, -n, -M, -h, -V) will
all put Roman numeral 9 in between 4 and 5. See here:

# echo "III\nII\nI\nV\nIV\nVII\nVI\nVIII\nX\nIX" | sort -g | nl

What I expect is to put 9 in between 8 and 10.

As I wrote above, I have tried -n as well. I tried -M because in
Romanian often the months are written with Roman numerals (I to XII),
but that also failed. -h and -V were not useful here either.

How do I sort in a pipe those roman numerals? I have written two bash
scripts roman_to_arab.sh and arab_to_roman.sh, but I do not know how
to adapt it to use it in pipes. Also, it may be too cumbersome to make
the conversion to arab digits, sort with -n and then convert back into
roman numerals...

Anyone has encounter this issue? Any ideas how to sort out this sort
issue? Of course, the easier will be if, indeed, the sort -g would
work as expected, e.g. if "_general_ numeric" will not be particular
to exclude Roman numerals...

At the moment I have to run this sort three times. First time to limit
it before IX (with grep -v -e IX -e '^X'), second time just grep "IX",
and third time to exclude all that starts with I and V: grep -v -e
"^I" -e "^V", and then put all together, like this:

( echo "III\nII\nI\nV\nIV\nVII\nVI\nVIII\nXI\nIX\nXII\nX" | sort -g | grep -v -e "IX" -e '^X' ; echo "III\nII\nI\nV\nIV\nVII\nVI\nVIII\nXI\nIX\nXII\nX" | grep -e "IX" ; echo "III\nII\nI\nV\nIV\nVII\nVI\nVIII\nXI\nIX\nXII\nX" | sort -g | grep -v -e "^I" -e "^V") | nl


I exclude here larger numerals, because at the moment I do not need
anything in that range...

Using the unicode gliphs also doesn't work:

# echo "Ⅲ\nⅡ\nⅠ\nⅣ\nⅤ\nⅨ\nⅥ\nⅦ\nⅧ\nⅫ\nⅪ\nⅩ" | sort -g | nl

either with -n, -V, -M, -h, etc.


Thanks,
 Ionel


Reply to: