根据域删除重复的电子邮件地址
Remove duplicate email addresses based on domain
我想根据域名删除重复的电子邮件地址。例如:
aa@example.com
bb@example.com
cc@bla.com
Should become:
aa@example.com
cc@bla.com
有人可以帮忙吗?我尝试使用 sort / uniq 和 awk,但还没有成功。
在php中:
<?php
$domains = []; // list of domains we have already included
$cleanList = []; // "clean" email list
$list = file('/path/to/email-list.txt'); // load the raw list
// loop over the raw list
foreach($list as $email) {
// extract the domain from the email
$domain = preg_replace('/^.*@/', '', $email);
// if the domain has not been taken yet
if(!in_array($domain, $domains)) {
// add it to the list of taken domains
array_push($domains, $domain);
// add the email to the clean list
array_push($cleanList, $email);
}
}
// write the clean list out to a file
file_put_contents('/tmp/clean-emails.txt', implode("\n", $cleanList));
我想根据域名删除重复的电子邮件地址。例如:
aa@example.com
bb@example.com
cc@bla.com
Should become:
aa@example.com
cc@bla.com
有人可以帮忙吗?我尝试使用 sort / uniq 和 awk,但还没有成功。
在php中:
<?php
$domains = []; // list of domains we have already included
$cleanList = []; // "clean" email list
$list = file('/path/to/email-list.txt'); // load the raw list
// loop over the raw list
foreach($list as $email) {
// extract the domain from the email
$domain = preg_replace('/^.*@/', '', $email);
// if the domain has not been taken yet
if(!in_array($domain, $domains)) {
// add it to the list of taken domains
array_push($domains, $domain);
// add the email to the clean list
array_push($cleanList, $email);
}
}
// write the clean list out to a file
file_put_contents('/tmp/clean-emails.txt', implode("\n", $cleanList));