2012-04-08 24 views

回答

1
sed -s 's/@/@\t/g' test.txt | uniq -f 1 | sed -s 's/@\t/@/g' 

第一SED在2個字段(名+域名)用製表符分隔的電子郵件,以便uniq的可移除重複的域時,跳過所述第一場,而最後SED移除的標籤。

3
#!/usr/bin/env perl 

use strict; use warnings; 
use Email::Address; 

my %data; 

while (my $line = <DATA>) { 
    my ($addr) = Email::Address->parse($line =~ /^(\S+)/); 
    push @{ $data{ $addr->host } }, $addr->original; 
} 

for my $addrs (values %data) { 
    if (@$addrs > 2) { 
     print "$addrs->[0]\n"; 
    } 
    else { 
     print "$_\n" for @$addrs; 
    } 
} 

__DATA__ 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
0

如果你不「介意的順序,只需要使用排序:

sort -t '@' -u -k 2,2 your_file 

如果你很介意的順序,做

gawk '{print NR "@" $0}' your_file | sort -t '@' -u -k 3,3 | sort -t '@' -k 1,1n | cut -d \@ -f 2-