GNU bug report logs - #20745
sort: add options to sort by IPv4/IPv6

Previous Next

Package: coreutils;

Reported by: "Silverman, Jeffrey X. -ND" <Jeffrey.X.Silverman.-ND <at> disney.com>

Date: Fri, 5 Jun 2015 17:32:01 UTC

Severity: wishlist

Full log


View this message in rfc822 format

From: Erik Auerswald <auerswal <at> unix-ag.uni-kl.de>
To: 20745 <at> debbugs.gnu.org
Subject: bug#20745: I would like to make a request for the sort command
Date: Mon, 8 Jun 2015 12:43:32 +0200
Hi,

On Mon, Jun 08, 2015 at 10:51:59AM +0100, Stephane Chazelas wrote:
> 2015-06-08 11:16:37 +0200, Erik Auerswald:
> [...]
> > FWIW I use 'sort' to sort IPv4 addresses in my ping_scan[1] script.
> > 
> > The info documentation for sort provides another example, log files
> > sorted by IP address and time stamp. That specific example even needs
> > two runs of sort, because sort lacks built-in support for IP addresses.
> > 
> > While IPv4 addresses are readily sorted by "sort -s -t '.' -k 1,1n -k
> > 2,2n -k 3,3n -k 4,4n", this is not the case for IPv6 addresses. Having
> > an option for sorting IP addresses that supports both IPv4 and IPv6
> > seems like a useful addition to me.
> [...]
> 
> I'm not even sure having a tool just for that specific task
> would make sense though. Here, it sounds more like a job for a
> high level language like perl/python... (what if I want to sort
> on roman numerals now, week day names, astrological signs...)

Well, IP addresses are often encountered on Internet connected computers.
;-)

> for instance, here using yash syntax (you can use named pipes or
> possibly coprocs with some other shells):
> 
> ip2hex() {
>   perl -MSocket=:all -nle '
>     print unpack "(H2)*", inet_pton(/:/?AF_INET6:AF_INET, $_)'
> }
> 
> mysort() {
>   (
>     exec 3>>|4
>     tee /dev/fd/3 |
>       cut -f1 3>&- | ip2hex 3>&- |
>       paste - /dev/fd/4 3>&-
>   ) | sort | cut -f2-
> }
> 
> mysort << EOF
> 127.0.0.1       blah
> 6.6.6.6         foo
> ::1             bar
> EOF
> 
> That's still quite awkward. A shame that piping capabilities in
> shells don't extend to  more  complex scenarii where the output
> of some command can be piped to two others the output of which
> can be merged back easily.
> 
> named pipes can be used for that, but cleaning up and
> restricting access to them makes their usage quite messy.
> 
> Of course, the whole thing can be done with perl.

I'd say the above is a very good reason for implementing the asked for
feature in sort.

Thanks,
Erik
-- 
Design your product to please the users.
                        -- Paul Graham




This bug report was last modified 6 years and 243 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.