Click here to get back home

extract all hotmail email addresses in a file and store in separate file

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
extract all hotmail email addresses in a file and store in separate file Dennis 06-18-2008
Posted by Dennis on June 18, 2008, 3:33 pm
Please log in for more thread options
Hi, I have a text file that contents a list of email addresses like
this:

"foo@yahoo.com"
"tom@hotmail.com"
"jerry@gmail.com"
"tommy@apple.com"

I like to

1. Strip out the " characters and just leave the email addresses on
each line.
2. extract out the hotmail addresses and store it into another file.
The hotmail addresses in the original file would be deleted.

Thanks for any help

Posted by cartercc on June 18, 2008, 4:01 pm
Please log in for more thread options
> Hi, I have a text file that contents a list of email addresses like
> this:
>
> "f...@yahoo.com"
> "t...@hotmail.com"
> "je...@gmail.com"
> "to...@apple.com"
>
> I like to
>
> 1. Strip out the " characters and just leave the email addresses on
> each line.
> 2. extract out the hotmail addresses and store it into another file.
> The hotmail addresses in the original file would be deleted.
>
> Thanks for any help

open INFILE, "<all_emails.txt";
open HOTMAIL, ">hotmail_only.txt";
open NOTHOTMAIL, ">not_hotmail.txt";
while(<INFILE>)
{
$_ =~ s/"//g;
print HOTMAIL if $_ =~ /hotmail/i;
print NOTHOTMAIL if $_ != /hotmail/i;
}
close INFILE;
close HOTMAIL;
close NOTHOTMAIL;

Posted by Walter Roberson on June 18, 2008, 4:06 pm
Please log in for more thread options
>> Hi, I have a text file that contents a list of email addresses like
>> this:
>
>> "f...@yahoo.com"
>> "t...@hotmail.com"
>> "je...@gmail.com"
>> "to...@apple.com"

>> I like to

>> 1. Strip out the " characters and just leave the email addresses on
>> each line.
>> 2. extract out the hotmail addresses and store it into another file.
>> The hotmail addresses in the original file would be deleted.

>open INFILE, "<all_emails.txt";
>open HOTMAIL, ">hotmail_only.txt";
>open NOTHOTMAIL, ">not_hotmail.txt";
>while(<INFILE>)
>{
> $_ =~ s/"//g;
> print HOTMAIL if $_ =~ /hotmail/i;
> print NOTHOTMAIL if $_ != /hotmail/i;
>}
>close INFILE;
>close HOTMAIL;
>close NOTHOTMAIL;

In your program, the match of /hotmail/ could occur on the left-hand size
of the @ . For example,

"my_other_account_is_hotmail@msn.com"

Your code would mistakenly file this in the wrong place.

Your code also does not satisfy the requirement that,
"The hotmail addresses in the original file would be deleted"
which requires that the original file be altered.
--
"For men are prone to go it blind along the calf-paths of the
mind To do what other men have done. They follow in the beaten
track, and out and in, and forth and back, and still their
devious course pursue, to keep the path that others do." -- Sam Walter Foss

Posted by cartercc on June 18, 2008, 4:36 pm
Please log in for more thread options
On Jun 18, 4:06 pm, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson)
wrote:
> In your program, the match of /hotmail/ could occur on the left-hand size
> of the @ . For example,
>
> "my_other_account_is_hotm...@msn.com"
>
> Your code would mistakenly file this in the wrong place.
>
> Your code also does not satisfy the requirement that,
> "The hotmail addresses in the original file would be deleted"
> which requires that the original file be altered.

My code was meant to be a rough pseudocode, not a tested application.
I just banged something out to show the logic, not expecting that
anyone would mistake it for a fully tested and debugged application. I
would expect it to fail the first time, but at least the outline of
the logic is there, even if it isn't complete.

CC

Posted by Antoninus Twink on June 18, 2008, 4:36 pm
Please log in for more thread options
On 18 Jun 2008 at 20:01, cartercc wrote:
>> I like to
>>
>> 1. Strip out the " characters and just leave the email addresses on
>> each line.
>> 2. extract out the hotmail addresses and store it into another file.
>> The hotmail addresses in the original file would be deleted.
>
> open INFILE, "<all_emails.txt";
> open HOTMAIL, ">hotmail_only.txt";
> open NOTHOTMAIL, ">not_hotmail.txt";
> while(<INFILE>)
> {
> $_ =~ s/"//g;
> print HOTMAIL if $_ =~ /hotmail/i;
> print NOTHOTMAIL if $_ != /hotmail/i;
> }
> close INFILE;
> close HOTMAIL;
> close NOTHOTMAIL;

Firstly, you mean !~ instead of !=. Secondly, referring to $_ all the
time is unnecessary. Try:

open INFILE, "< all_emails.txt";
open HOTMAIL, "> hotmail_only.txt";
open NOTHOTMAIL, "> not_hotmail.txt";
while(<INFILE>)
{
s/"//g;
if (/hotmail/i) {
print HOTMAIL;
} else {
print NOTHOTMAIL;
}
}
close INFILE;
close HOTMAIL;
close NOTHOTMAIL;

You might also like to include some error-checking, and avoid
hard-coding the paths.


Similar ThreadsPosted
Regex for finding email addresses inside text file January 27, 2005, 1:44 am
how to separate all but www addresses? September 26, 2004, 1:41 pm
Validating email addresses August 10, 2004, 9:26 pm
parsing email addresses July 18, 2005, 10:32 pm
Regexp for email addresses. February 14, 2007, 4:55 pm
FAQ 4.65 How can I store a multidimensional array in a DBM file? May 12, 2005, 11:03 am
FAQ: How can I store a multidimensional array in a DBM file? October 10, 2004, 5:10 pm
FAQ 4.65 How can I store a multidimensional array in a DBM file? February 13, 2005, 12:03 am
FAQ 4.65 How can I store a multidimensional array in a DBM file? July 28, 2005, 10:03 am
FAQ 4.65 How can I store a multidimensional array in a DBM file? September 17, 2005, 10:03 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap