sort(1) sorting IP (v4) addresses (INET_ATON?)

Chris H bsd-lists at BSDforge.com
Wed Nov 29 18:47:21 UTC 2017


On Wed, 29 Nov 2017 10:37:25 -0800 "Craig Leres" <leres at ee.lbl.gov> said

> On 11/29/17 10:35, Chris H wrote:
> > 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.
> 
> % grep sortip ~/.cshrc
> a sortip "sort -t. +0 -1n +1 -2n +2 -3n +3 -4n"
> 
> 		Craig
Brilliant! Craig, you're a rock star. Thanks!

--Chris




More information about the freebsd-hackers mailing list