CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Tough Extract for Email Address

 



rfransix
Novice

Apr 1, 2011, 1:13 PM

Post #1 of 6 (2006 views)
Tough Extract for Email Address Can't Post

I've been using awk to extract the email address from source files, but this attached file has be frantic...any ideas are very much appreciated.

Here's the awk that works perfectly, but against the rfi.txt file, it only pulls the first column addresses...each line extends to thousands of characters.

gawk "{ for (i=1;i<=NF;i++) { if ( $i ~ /[[:alnum:]]@[[:alnum:]]/ ) { print $i } } }" "%1" > "%2"

And here's the rfi.txt file...it is a saved search file from a database.
Attachments: rfi.txt (81.2 KB)


FishMonger
Veteran / Moderator

Apr 1, 2011, 2:58 PM

Post #2 of 6 (2002 views)
Re: [rfransix] Tough Extract for Email Address [In reply to] Can't Post

Your file format is not plain ascii, so this may need a slight adjustment.


Code
#!/usr/bin/perl 

use strict;
use warnings FATAL => 'all';
use Email::Find;
use File::Slurp;

my @email_addresses;
my $finder = Email::Find->new(sub {
my($email, $orig_email) = @_;
push @email_addresses, $email->format;
});

my $file_contents = read_file('rfi.txt');
$finder->find(\$file_contents);

print join("\n", @email_addresses);



rfransix
Novice

Apr 1, 2011, 3:27 PM

Post #3 of 6 (1999 views)
Re: [FishMonger] Tough Extract for Email Address [In reply to] Can't Post

Were you success extracting +380 addresses from the rfi.txt file with this code? I was unable to get more than 8.


FishMonger
Veteran / Moderator

Apr 1, 2011, 4:55 PM

Post #4 of 6 (1996 views)
Re: [rfransix] Tough Extract for Email Address [In reply to] Can't Post

I was able to extract 483 email addresses.


(This post was edited by FishMonger on Apr 1, 2011, 4:57 PM)


rfransix
Novice

Apr 1, 2011, 7:03 PM

Post #5 of 6 (1989 views)
Re: [FishMonger] Tough Extract for Email Address [In reply to] Can't Post

Loading all the right modules helps...works perfectly. Thanks for the attention to details.


FishMonger
Veteran / Moderator

Apr 1, 2011, 7:35 PM

Post #6 of 6 (1987 views)
Re: [rfransix] Tough Extract for Email Address [In reply to] Can't Post

You're welcome

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives