> -----Original Message-----
> From: J. Kent Busbee, Jr. [mailto:buz@penwel.com]
> Sent: Thursday, June 19, 2003 1:14 PM
> To: nolug@joeykelly.net
> Subject: RE: [Nolug] Sorting lists of domains
>
>
> > Ah, but does this work for an arbitrary number of subdomains?
> > That's the
> > tricky one. I know that my solution is cumbersome. I'd like
> > to see one that
> > handles an arbitrary number of subdomains, but is cleaner
> > than mine. I know
> > it can be done.
> >
>
> Ok... Try this one for up to 4 subdomains where t1 is the
> unsorted file
>
> awk -F. '{if (NF==1) x = "...."; if (NF==2) x = "..."; \
> if (NF==3) x = ".."; if (NF==4) x = "."; \
> if (NF==5) x = ""; print x $0}' t1 \
> | sort -f. -k 5,5 -k 4,4 -k 3,3 -k 2,2
>
>
Don't know if it's cleaner or not - but this handles as many subdomains as
you throw at it.
awk -F. '{dom="";for(i=NF;i>0;i=i-1){dom = dom "." $i;};print dom;}'
test.sort | sort | awk -F. '{dom="";for(i=NF;i>0;i=i-1){dom = dom "."
$i;};print substr(dom,2,length(dom)-2);}'
All one line of course.
Produces this:
1.a.com
5.a.com
d.com
3.e.edu
2.b.gov
c.mil
4.f.net
h.net
g.uk
___________________
Nolug mailing list
nolug@nolug.org
Received on 06/19/03
This archive was generated by hypermail 2.2.0 : 12/19/08 EST