我想删除重复的电子邮件地址基础上的域名。例如:
aa@example.com
bb@example.com
cc@bla.com
Should become:
aa@example.com
cc@bla.com有人能帮忙吗?我试过使用sort / uniq和awk,但还没有让它正常工作。
发布于 2022-01-14 00:09:57
在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));https://stackoverflow.com/questions/70704509
复制相似问题