Re: [Nolug] Sorting lists of domains

From: -ray <ray_at_ops.selu.edu>
Date: Wed, 18 Jun 2003 19:00:25 -0500 (CDT)
Message-ID: <Pine.LNX.4.44.0306181848370.3003-100000@romulus.csd.selu.edu>

Doesn't work on my test set:

h.net
3.e.edu
peaf.fde.a.com
c.mil
d.com
x1.a.com
4.f.net
g.uk
2.b.gov
c5.a.com

And weird things will happen when mixing numerical and alphabetical
sorting...

How about some perl? This will do up to 2 sub-domains...but can be
expanded: (watch for line wraps)

#!/usr/bin/perl

while (<STDIN>) { push(@n,$_); }
@s= sort {
        ($a =~ /(\w+)\.(\w+)$/)[0] cmp ($b =~ /(\w+)\.(\w+)$/)[0]
     or ($a =~ /(\w+)\.(\w+)\.(\w+)$/)[0] cmp ($b =~ /(\w+)\.(\w+)\.(\w+)$/)[0]
     or ($a =~ /(\w+)\.(\w+)\.(\w+)\.(\w+)$/)[0] cmp ($b =~ /(\w+)\.(\w+)\.(\w+)\.(\w+)$/)[0]
         } @n;
foreach $n (@s) {print $n;}

perl rules... ;)

ray

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Ray DeJean  				       	 http://www.r-a-y.org
Systems Engineer                    Southeastern Louisiana University
IBM Certified Specialist  	      AIX Administration, AIX Support
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
On Wed, 18 Jun 2003, Dustin Puryear wrote:
> This is what I came up with. I know I can get this smaller.
> 
> #!/bin/sh
> 
> PATH=/bin:/usr/bin
> 
> reverse() {
>          rm $2
>          for string in `cat $1`; do
>                  n=1
>                  delim=""
>                  dc=`echo $string | cut -d. -f$n`
>                  newstring=""
>                  while [ ! -z "$dc" ]; do
>                          [ $n -ge 2 ] && delim="."
>                          newstring="$dc$delim$newstring"
>                          n=`expr $n + 1`
>                          dc=`echo $string | cut -d. -f$n`
>                  done
>                  echo $newstring >> $2
>          done
> }
> 
> reverse text text.1
> sort text.1 > text.2
> reverse text.2 text.3
> 
> 
> At 03:43 PM 6/18/2003 -0500, you wrote:
> 
> >Let's see who can do this in a shell script with the least amount of code.
> >
> >At 01:38 PM 6/18/2003 -0500, you wrote:
> >
> >>The list has been a little quiet (down ?) for a couple of days, so here's 
> >>an easy question.
> >>
> >>I'm looking for a utility - Linux or otherwise - to take a list of 
> >>domains or even email
> >>addresses and sort them from the TLD down. In other words, treating 
> >>periods as field
> >>delimiters and sorting fields from right to left. So, for example:
> >>
> >>h.net
> >>3.e.edu
> >>c.mil
> >>d.com
> >>1.a.com
> >>4.f.net
> >>g.uk
> >>2.b.gov
> >>5.a.com
> >>
> >>would sort to
> >>
> >>1.a.com
> >>5.a.com
> >>d.com
> >>3.e.edu
> >>2.b.gov
> >>c.mil
> >>4.f.net
> >>h.net
> >>g.uk
> >>
> >>Someone must have made a tool to do this, but I can't find one. I could 
> >>probably cobble
> >>something together in Perl, but I don't want to reinvent the wheel. All I 
> >>get from
> >>web searches are mailing list programs and domain registration tools.
> >>
> >>Thanks.
> >>
> >>
> >>Mark Robinson
> >>
> >>___________________
> >>Nolug mailing list
> >>nolug@nolug.org
> >
> >
> >---
> >Dustin Puryear <dustin@puryear-it.com>
> >Puryear Information Technology
> >Windows, UNIX, and IT Consulting
> >http://www.puryear-it.com
> >
> >___________________
> >Nolug mailing list
> >nolug@nolug.org
> >
> 
> 
> ---
> Dustin Puryear <dustin@puryear-it.com>
> Puryear Information Technology
> Windows, UNIX, and IT Consulting
> http://www.puryear-it.com
> 
> ___________________
> Nolug mailing list
> nolug@nolug.org
> 
___________________
Nolug mailing list
nolug@nolug.org
Received on 06/18/03

This archive was generated by hypermail 2.2.0 : 12/19/08 EST