Norbert Kiesel wrote: > I needed to sort some text by IP addresses, and there does not seem to > be a good way to do it. They only trick I found was "-n -t. -k1,1 -k2,2 > -k3,3 -k4.4" or so, but that is kind of ugly.
The coreutils manual suggests: sort -t '.' -k 1,1n -k 2,2n -k 3,3n -k 4,4n It is a bit ugly, but it's fine for scripts. Pádraig Brady <[EMAIL PROTECTED]> writes: > For IPV4 this is too specific IMHO. I tend to agree. "sort" should have a way to plug in arbitrary comparison functions. For example, it might add an option to open a pipe to another process, feed it two lines, and expect a response "<", "=", ">". Or perhaps there's a better way; but the point is that these algorithms should not all have to be hardwired into "sort". > You may have a point though for comparing IPV6 addresses. > I can't figure out a general method at least. Yes, it'd be tricky to reduce it to a -k recipe even if we added support for comparing hexadecimal numbers to 'sort' (a far more likely candidate for inclusion), because of mixed addresses and the :: notation. E.g., comparing 0:0:0:0:0:FFFF:129.144.52.38 to FF01::101 would be quite tricky with just -k and hex. Better would be support for arbitrary comparison plugins. _______________________________________________ Bug-coreutils mailing list [email protected] http://lists.gnu.org/mailman/listinfo/bug-coreutils
