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

Re: sort (-g) [offtopic]



On 18-02-2018, at 14h 44'27", David Wright wrote about "Re: sort (-g) [offtopic]"
> Any script that reads stdin and writes stdout can be used in a pipe.
> That's one of the guiding principles of unix.

I change the scripts to use read if $# is zero. I could use them in
pipes now. But that is not helping me.

> 
> After they've done Roman numerals, they can settle down and do
> yan tan tethera in all dialects.
> https://en.wikipedia.org/wiki/Yan_Tan_Tethera

Well, I do not see those to use any symbols. It is like asking the
computer to sort numerically one two three four ... in whatever
language. This will fail.

Roman numerals never fail from usage, they should be considered, in my
opinion.

> You shouldn't sort like that. If you've got records to sort which have
> an unsortable field like Roman months, then write some thing in sed,
> say, that can do the conversion. Now read your records, say:
> field1 field2 XII field3 field4
> field1 field2 IV field3 field4
> and prefix each record with the numeric representation;
> 12 field1 field2 XII field3 field4
> 04 field1 field2 IV field3 field4
> Now sort that, then throw away the first field with cut. You should
> never have to worry about converting things back!

My programing capacities in sed or awk must be improved in order to
accomplish that. In the mean time, since I only need to move the 5th
line into 9th position (before 10) I can supliment the sort with a sed
pipe:

some input | sort -k2,2 | sed -e '5h;5d;10H;10x'

This of course if all the Roman numerals from 1 to 12 are present...
and only once..., hm...

Thank you for the hints, David.

Ionel


Reply to: