[TriLUG] sort(1) and IPAs

Tom Bryan tbryan at python.net
Wed Mar 6 20:47:58 EST 2002


On Wednesday 06 March 2002 09:43 pm, Mike wrote:
> 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/"

Why is the sed bit necessary?  The sort seems to work for me without the sed 
part.  

---Tom



More information about the TriLUG mailing list