[TriLUG] sort(1) and IPAs
Rodent of Unusual Size
Ken.Coar at Golux.Com
Thu Mar 7 06:03:34 EST 2002
Tom Bryan wrote:
>
> > #!/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/"
Bingo. Of course, the pattern doesn't match partial IPAs like
123.17, but it seems to work nevertheless. I'll try to figure
out why when I'm more awake. Thanks!
> Why is the sed bit necessary? The sort seems to work for me
> without the sed part.
Try sorting this with just the sort command above:
211.155.13
53.7.91.173
211.155.12
12.33
56.10.43
211.155.200.1
25.39.85.245
211.155.200.10
211.16.1
No joy. However, adding '-n' fixes that and gets rid of the seds.
Cool.
--
#ken P-)}
Ken Coar, Sanagendamgagwedweinini http://Golux.Com/coar/
Author, developer, opinionist http://Apache-Server.Com/
"Millennium hand and shrimp!"
More information about the TriLUG
mailing list