help to separate name and email domain


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help to separate name and email domain
# 1  
Old 09-06-2010
Tools help to separate name and email domain

hie everyone,

Need your help, i have a file which consists list of email addresses as below example:-
jaja@email.com
kaka@myemail.com
baba@youremail.com.
lala@email.com

i need a script to separate the name and email domian, and count the number of unique domain from the file. From the example above, i need a script which can give below result:-

2 email.com
1 myemail.com
1 youremail.com

thanks you in advanced.

The one
Rammy
# 2  
Old 09-06-2010
Try:
Code:
awk -F@ 'END{for(i in A)print A[i],i}{A[$2]++}' infile

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 09-06-2010
Another way, assuming this is a long list in random order and you want the output in sorted order of domain name.

Code:
awk -F\@ '{print $2}' filename | sort | uniq -c

   2 email.com
   1 myemail.com
   1 youremail.com.

The trailing full-stop on the last address may be a typo in the original data.

Last edited by methyl; 09-06-2010 at 06:25 PM.. Reason: show results
# 4  
Old 09-06-2010
Code:
cut -d @ -f2 < infile |sort |uniq -c |sort -rn



---------- Post updated at 11:59 AM ---------- Previous update was at 11:58 AM ----------

Quote:
Originally Posted by Scrutinizer
Try:
Code:
awk -F@ 'END{for(i in A)print A[i],i}{A[$2]++}' infile

Get sorted result directly.

Code:
awk -F@ 'END{for(i in A)print A[i],i |"sort -nr"}{A[$2]++}' infile

# 5  
Old 09-07-2010
Quote:
Originally Posted by rdcwayx
Code:
cut -d @ -f2 < infile |sort |uniq -c |sort -rn



---------- Post updated at 11:59 AM ---------- Previous update was at 11:58 AM ----------



Get sorted result directly.

Code:
awk -F@ 'END{for(i in A)print A[i],i |"sort -nr"}{A[$2]++}' infile

Or just:
Code:
awk -F@ 'END{for(i in A)print A[i],i }{A[$2]++}' infile | sort -rn

# 6  
Old 09-07-2010
You can archieve it with perl withou using any external process:
Code:
perl -e 'while(<>){chomp;/^[^@]+@([^@]+)$/;$h{$1}++;}
foreach $k (sort { $h{$b} <=> $h{$a} } keys %h)  {print $h{$k}." ".$k."\n";} infile

Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Solaris

When do you need a separate service/IO domain?

Looking at latest recommendations - http://www.oracle.com/technetwork/server-storage/vm/ovmsparc-best-practices-2334546.pdf - specifically regarding domain roles. At the moment, we just have a physical host, primary control domain and then guest ldoms. We then export things like vdisks,vnet etc... (2 Replies)
Discussion started by: psychocandy
2 Replies

2. Red Hat

Not able to send an email from a particular domain.

HI Gurus, I have a RHEL (5.5) VM. I am able to send email to a particular domain abc.com but when I am trying to send a different domain(xyz.com) it is not working can you please throw some light on how to start debugging this issue. Thanks in advance. RK (0 Replies)
Discussion started by: rama krishna
0 Replies

3. Shell Programming and Scripting

Using top command to email if process is exceeding 25% and sending an email alert if so

This is my first time writing a script and Im having some trouble, Im trying to use the top command to monitor processes and the amount of CPU usage they require, my aim is to get an email if a process takes over a certain percentage of CPU usage I tried grep Obviosly that hasnt worked, Any... (8 Replies)
Discussion started by: jay02
8 Replies

4. UNIX for Advanced & Expert Users

Sending email to different domain

Hi, I am looking for info based on direct experience in using DataStage EE with Unix. A scenario in the client remote desktop I work for company Switch, my client is Master. Notification Activity Stage (IBM Asential Data Stage component) SMTP Mail server name is blank. Sender... (1 Reply)
Discussion started by: dsnaveen
1 Replies

5. Windows & DOS: Issues & Discussions

How to: Linux BOX in Windows Domain (w/out joining the domain)

Dear Expert, i have linux box that is running in the windows domain, BUT did not being a member of the domain. as I am not the System Administrator so I have no control on the server in the network, such as modify dns entry , add the linux box in AD and domain record and so on that relevant. ... (2 Replies)
Discussion started by: regmaster
2 Replies

6. Solaris

can't email my own domain

I am not able to send email only to my own domain with sendmail. I am having trouble determining if the problem is name resolution on the box in question, or if the email is getting stopped at the mail relay/spam appliance. I would appreciate any insights into this problem. Could it be the... (0 Replies)
Discussion started by: lscritch
0 Replies

7. UNIX for Dummies Questions & Answers

Send email with attachement-Getting connection refused by domain

Hi all, I am a newbie to unix. I need to send an email with an attachment in unix to some id like abc@some_company.com Code i have used is ------------Code--------------------------- #!/bin/ksh set -x #set -n #cript: unix_mail_withattachments.ksh # Aurthor: Ravin Maharaj #... (1 Reply)
Discussion started by: samuelc
1 Replies
Login or Register to Ask a Question