Ethan Baldridge wrote:
> Pádraig Brady wrote:
>
>> Also it's quite easy to achieve with existing tools:
>> awk '{print length, $0}' <file | sort -n | cut -f2- -d' '
>
> That doesn't help in the case where you only need to sort on a given key in
> the file.
> A more complicated awk pattern (or a cut beforehand) could handle that as
> well,
> but it seems worth it to have a trivial flag to sort for that case.
Fair point. Note another option is to right align the field if possible
and sort with a locale where space is significant. For illustration:
printf "%100s\n" a bbb cc | LANG=C sort | sed 's/^ *//'
Of course 100 would need to be changed to be larger than any item.
>> What might be better would be to add an option
>> to `wc` to get it to prepend various counts to a line
>> (words, chars, bytes, cells), which then could be
>> sorted and stripped as above.
>
> I'd argue on terms of obviousness: "I'm trying to sort these differently... I
> should look at the options for sort!"
Well lots of things boil down to sorting so I think we've to be especially
careful with adding things to `sort`. While your suggestion is useful
and is simple to implement I'm worried that it's not needed often enough
to allocate a sort option for it. Also it's easy enough to achieve with
a little sed & awk around the sort even for the single field case.
Having thought about it more I'm a little more disposed to this patch,
but I'm still 60:40 against it.
cheers,
Pádraig.
_______________________________________________
Bug-coreutils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-coreutils