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
Try:
awk -F@ 'END{for(i in A)print A,i}{A[$2]++}' infile
methyl
September 6, 2010, 5:21pm
3
Another way, assuming this is a long list in random order and you want the output in sorted order of domain name.
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.
rdcwayx
September 6, 2010, 9:59pm
4
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.
awk -F@ 'END{for(i in A)print A,i |"sort -nr"}{A[$2]++}' infile
rdcwayx:
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.
awk -F@ 'END{for(i in A)print A,i |"sort -nr"}{A[$2]++}' infile
Or just:
awk -F@ 'END{for(i in A)print A,i }{A[$2]++}' infile | sort -rn
Klashxx
September 7, 2010, 4:45am
6
You can archieve it with perl withou using any external process:
perl -e 'while(<>){chomp;/^[^@]+@([^@]+)$/;$h{$1}++;}
foreach $k (sort { $h{$b} <=> $h{$a} } keys %h) {print $h{$k}." ".$k."\n";} infile