For Programmers: Free Programming Magazines  


Home > Archive > AWK > October 2006 > how to sort an email address









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author how to sort an email address
rogv24@yahoo.com

2006-10-12, 6:57 pm


Thanks

rogv24@yahoo.com

2006-10-12, 6:57 pm



Sorry, I needed to say just the domain.
rog...@yahoo.com wrote:
> Thanks


Ed Morton

2006-10-12, 6:57 pm

rogv24@yahoo.com wrote:
>
> Sorry, I needed to say just the domain.
> rog...@yahoo.com wrote:
>
>
>


awk 'BEGIN{print "just the domain"; exit}'
Juergen Kahrs

2006-10-12, 6:57 pm

Ed Morton wrote:

>
> awk 'BEGIN{print "just the domain"; exit}'


Ed, this can be done even faster and more elegant:

awk 'BEGIN{print "just the domain" }'

Tested, should work on each POSIX-compliant system.
Kenny McCormack

2006-10-12, 6:57 pm

In article <4p3ic8Fh4h4aU1@individual.net>,
Juergen Kahrs <Juergen.KahrsDELETETHIS@vr-web.de> wrote:
>Ed Morton wrote:
>
>
>Ed, this can be done even faster and more elegant:
>
> awk 'BEGIN{print "just the domain" }'
>
>Tested, should work on each POSIX-compliant system.


I believe that fails under Solaris "old awk" (the one preferred by and
used by newbies everywhere). Hence Ed's reason for posting as he did
when posting to this ng.

Juergen Kahrs

2006-10-12, 6:57 pm

Kenny McCormack wrote:
> In article <4p3ic8Fh4h4aU1@individual.net>,
> Juergen Kahrs <Juergen.KahrsDELETETHIS@vr-web.de> wrote:
>
> I believe that fails under Solaris "old awk" (the one preferred by and
> used by newbies everywhere). Hence Ed's reason for posting as he did
> when posting to this ng.
>


Indeed, you are right. Surprise surprise.
I just tested this on Solaris 8. Now I know
why the "exit" statement is in the "Hello world"
script of Wikipedia's AWK entry.


> oawk 'BEGIN{print "just the domain" }'

just the domain

^C
> oawk 'BEGIN{print "just the domain" ; exit }'

just the domain
> uname -a

SunOS br2ssp01 5.8 Generic_108528-29 sun4u sparc SUNW,Ultra-60
Loki Harfagr

2006-10-14, 6:55 pm

Le Tue, 10 Oct 2006 17:10:00 -0500, Ed Morton a écrit_:

> rogv24@yahoo.com wrote:
>
> awk 'BEGIN{print "just the domain"; exit}'


Nice and clean, Ed, but I believe what he needs is much more complete :-)

$ echo "Sorry, I needed to say"|awk '{print "just","the","domain"}'
Mag Gam

2006-10-15, 6:59 pm

/tmp/email is where your email addresses are:

To sort your email address
gawk -F@ '{a[NR]=$1} END { n=asort(a,d); for (i=1;i<=n;i++) print d[i]}
' /tmp/email

To sort your domain
gawk -F@ '{a[NR]=$2} END { n=asort(a,d); for (i=1;i<=n;i++) print d[i]}
' /tmp/email

HTH


rogv24@yahoo.com wrote:[color=darkred]
> Sorry, I needed to say just the domain.
> rog...@yahoo.com wrote:

Jon LaBadie

2006-10-15, 9:56 pm

rogv24@yahoo.com wrote:
>
> Sorry, I needed to say just the domain.
> rog...@yahoo.com wrote:
>


I assume you want addresses like abc@bar.org and xyz@foo.bar.org
to sort together as part of a bar.org grouping. This duplicates
the parts of the email address at the front of each line in
reverse order, sorts then cuts off the addition.

awk -F'[@.]' '
BEGIN { cmd = "sort | cut -d\"|\" -f2" }
{
s = $NF
for (i = NF - 1 ; i >= 1 ; i--)
s = s " " $i
print s " |" $0 | cmd
}'

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com