[TriLUG] sort(1) and IPAs

Mike myname17 at bellsouth.net
Wed Mar 6 11:43:22 EST 2002


Try ipsort.sh [Not mine, unsure where I picked it up].  The sed line is
long, it will probable wrap in e-mail, be sure to unwrap it.

Mike

#!/bin/sh
## ipsort
## A filter to sort a file like /etc/hosts by IP address.
#
ip='[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*'
sed "s/^\($ip\)/\1./" | sort -n -t. +0 -1 +1 -2 +2 -3 +3 -4 | sed
"s/^\($ip\)./\1/"

-----Original Message-----
From: trilug-admin at trilug.org [mailto:trilug-admin at trilug.org] On Behalf
Of Rodent of Unusual Size
Sent: Wednesday, March 06, 2002 10:44 AM
To: Triangle Linux Users Group
Subject: [TriLUG] sort(1) and IPAs

Is there some magic set of options to sort(1) that will cause
it to correctly sort IP addresses correctly?  Particularly when
the data set will contain 2-, 3-, and 4-octet numbers?  (E.g.,
57.3, 57.3.4, and 57.3.4.211)
-- 
#ken	P-)}

Ken Coar, Sanagendamgagwedweinini  http://Golux.Com/coar/
Author, developer, opinionist      http://Apache-Server.Com/

"Millennium hand and shrimp!"
_______________________________________________
TriLUG mailing list
    http://www.trilug.org/mailman/listinfo/trilug
TriLUG Organizational FAQ:
    http://www.trilug.org/~lovelace/faq/TriLUG-faq.html




More information about the TriLUG mailing list