从包含100多个用户的文件中提取电子邮件

时间:2015-10-12 22:21:07

标签: linux awk sed count grep

我无法完全解决这个问题。我正在尝试从电子邮件地址列表中输出包含电子邮件地址列表的文件。如果分配给该列表域中任何给定的电子邮件地址超过100个,我需要将这些电子邮件输出到文件中。

emaillist.txt文件将包含:

5000 occurrences of userID@yahoo.com 
2000 occurrences of userID@aol.com
100 occurrences of userID@rr.com  
10 occurrences of userID@whatever.com

cut -d @ -f 2 emailist.txt | sort | uniq -c | sort -rn

输出

5000 yahoo.com 
2000 aol.com 
100 rr.com 
10 whatever.com

现在我知道每个域中有多少封电子邮件的数量,我只想要新文件中包含超过100个用户的电子邮件地址。

2 个答案:

答案 0 :(得分:1)

假设您的文件仅包含电子邮件。使用以下awk可以解决您的问题。

awk '{split($0, a, "@");} NR==FNR{mp[a[2]]++; next} (mp[a[2]]>=100)' emaillist.txt  emaillist.txt
                                                            ^^^ modify to whatever you need  

<强>样本

lo@ubuntu:~$ cat emaillist.txt 
userID@yahoo.com 
userID1@yahoo.com 
userID2@yahoo.com 
userID@aol.com
userID@rr.com  
userID@whatever.com
lo@ubuntu:~$ awk '{split($0, a, "@");} NR==FNR{mp[a[2]]++; next} (mp[a[2]]>1)' emaillist.txt  emaillist.txt 
userID@yahoo.com 
userID1@yahoo.com 
userID2@yahoo.com 

答案 1 :(得分:1)

这应该做你想要的:

cut -d @ -f 2 email.txt | sort | uniq -c | awk '$1 >= 100 {print $2}' | while read e; do grep "@$e$" email.txt >> emailkeep.txt; done