[SunHELP] sort

Ramon Gonzalez sunhelp at sunhelp.org
Fri Jul 27 18:26:57 CDT 2001


Wow. Talk about driving a tank to the grocery store. Sometimes unix tools
work just fine.

-----Original Message-----
From: Paul Dlug [mailto:pdlug at portjeff.net]
Sent: Friday, July 27, 2001 12:52 PM
To: sunhelp at sunhelp.org
Subject: Re: [SunHELP] sort


sortip.pl:
#!/usr/bin/perl

use strict;

my $file = $ARGV[0] || '-';

open(FILE, $file) or
  die("Usage: sortips.pl file (or standard input)\n");
print join("\n", sort sortips <FILE>), "\n";
close(FILE);

sub sortips {
 chomp($a = $a);
 chomp($b = $b);
 my ($aa, $ab, $ac, $ad) = split /\./, $a;
 my ($ba, $bb, $bc, $bd) = split /\./, $b;
 return ($aa <=> $ba) || ($ab <=> $bb) || ($ac <=> $bc) || ($ad <=> $bd);
}



Then just:
chmod +x sortip.pl

Then:
sortip.pl filename
or
cat ips.txt | sortip.pl

--Paul


---------- Original Message ----------------------------------
From: william.x.ng at verizon.com
Reply-To: sunhelp at sunhelp.org
Date: Fri, 27 Jul 2001 14:09:50 -0400

>
>Does anyone know how to sort this
>146.13.10.30
>146.13.1.30
>146.13.11.30
>146.13.1.31
>146.13.1.4
>146.13.9.30
>148.13.1.30
>148.13.2.10
>
>to
>
>146.13.1.4
>146.13.1.30
>146.13.1.31
>146.13.9.30
>146.13.10.30
>146.13.11.30
>148.13.1.30
>148.13.2.10
>
>Thanks
>Will
>
>_______________________________________________
>SunHELP maillist  -  SunHELP at sunhelp.org
>http://www.sunhelp.org/mailman/listinfo/sunhelp
>
_______________________________________________
SunHELP maillist  -  SunHELP at sunhelp.org
http://www.sunhelp.org/mailman/listinfo/sunhelp



More information about the SunHELP mailing list