从超过 100 个用户的文件中提取电子邮件

Extract emails from file with more than 100 users

我无法完全解决这个问题。我正在尝试从电子邮件地址列表中输出一个包含电子邮件地址列表的文件。如果有超过 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 个用户的电子邮件地址。

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

awk '{split([=10=], 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([=11=], a, "@");} NR==FNR{mp[a[2]]++; next} (mp[a[2]]>1)' emaillist.txt  emaillist.txt 
userID@yahoo.com 
userID1@yahoo.com 
userID2@yahoo.com 

这应该可以满足您的要求:

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