From owner-freebsd-hackers@freebsd.org Wed Nov 29 19:09:50 2017 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C9D1BDB93B0 for ; Wed, 29 Nov 2017 19:09:50 +0000 (UTC) (envelope-from freebsd-rwg@pdx.rh.CN85.dnsmgr.net) Received: from pdx.rh.CN85.dnsmgr.net (br1.CN84in.dnsmgr.net [69.59.192.140]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9B31217DF for ; Wed, 29 Nov 2017 19:09:49 +0000 (UTC) (envelope-from freebsd-rwg@pdx.rh.CN85.dnsmgr.net) Received: from pdx.rh.CN85.dnsmgr.net (localhost [127.0.0.1]) by pdx.rh.CN85.dnsmgr.net (8.13.3/8.13.3) with ESMTP id vATJ9eR1019942; Wed, 29 Nov 2017 11:09:40 -0800 (PST) (envelope-from freebsd-rwg@pdx.rh.CN85.dnsmgr.net) Received: (from freebsd-rwg@localhost) by pdx.rh.CN85.dnsmgr.net (8.13.3/8.13.3/Submit) id vATJ9eir019941; Wed, 29 Nov 2017 11:09:40 -0800 (PST) (envelope-from freebsd-rwg) From: "Rodney W. Grimes" Message-Id: <201711291909.vATJ9eir019941@pdx.rh.CN85.dnsmgr.net> Subject: Re: sort(1) sorting IP (v4) addresses (INET_ATON?) In-Reply-To: <1f2d985d685f66ad01ff2810cbb941c9@udns.ultimatedns.net> To: bsd-lists@BSDforge.com Date: Wed, 29 Nov 2017 11:09:40 -0800 (PST) CC: FreeBSD Hackers X-Mailer: ELM [version 2.4ME+ PL121h (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Mailman-Approved-At: Wed, 29 Nov 2017 20:23:43 +0000 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Nov 2017 19:09:50 -0000 > I'm constantly dealing with IPv4 addresses (millions). Sorting the mass > is never perfect, and I'm forced to *visually* fix those out of order. > Yet I continue to (later) find some I've missed -- I'm sick of it! > Thus far, I've found I attain the best results with sort(1): > > sort -t . -k 4,4n -k 3,3n -k 2,2n ./TCPLIST | sort -g>./SORTED > > Which ends up pretty damn close. But not perfect. :( > Then it occurred to me that adding INET_ATON to sort, allowing for > an additional -inet option to sort(1) for IP addresses -- hell if > MySQL can provide it[1], why the heck can't sort(1)? > Else I guess I'll have to try and give a shot at cobbling up a C > utility to manage it. But seems like too much work for something > that'll only accomplish one thing. :( > > Thanks for any thoughts, or further insight. > > [1] https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_inet-aton The old school on this is you do a substitue of the . for a and then just use sort -n on that then munge it back to have the .'s, Though I would not be opposed to sort learning about inet numbers, it should not be -inet as you would want to be able to apply this to fields as in 4i to sort the 4th field as an inet number. Actually I guess you need both to be orthagnal with -n and others. -- Rod Grimes rgrimes@freebsd.org