[conspire] Puzzle: How do you sort IP address lists?
Tim Utschig
tim at tetro.net
Tue Nov 7 14:44:22 PST 2006
On Tue, Nov 07, 2006 at 12:16:25PM -0800, Rick Moen wrote:
>
> (I'll also really admire someone's elegant solution in, e.g., Python,
> Perl, or Ruby -- but I'm just boggling at how non-obvious my "sort"
> solution seems, and want to compare notes.)
>
I wouldn't call mine elegant, but the last time I tried to figure out
how to do it using sort I gave up and used Perl...
:r!grep ipsort ~/.bashrc
alias ipsort='perl -MSocket -lne '\''$ips{inet_aton($_)}++; END { for (sort keys %ips) { while($ips{$_}--) { print inet_ntoa($_); } } }'\'
alias ipsortu='perl -MSocket -lne '\''$ips{inet_aton($_)} = 1; END { print inet_ntoa($_) for sort keys %ips }'\'
--
- Tim Utschig <tim at tetro.net>
More information about the conspire
mailing list