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 cartercc on June 18, 2008, 4:02 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 szr on June 18, 2008, 4:05 pm
Please log in for more thread options
Dennis wrote:
> 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

To get you started, assuming there are no escaped quotes in between:

while (m!"([^"]+?)"!g) {
if ($1 =~ m!\@hotmail\.com!) {
... do something with $1
}
else { ... }
}


Or if you are using an array:

foreach my $email (map { s!"([^"]+?)"!$1!g; $_; } @email_list) {
if ($email =~ m!\@hotmail\.com!) {
...
}
else { ... }
}

(Note, untested, but should give a starting point.)

--
szr



Posted by Rui Maciel on June 18, 2008, 4:53 pm
Please log in for more thread options
On Wed, 18 Jun 2008 12:33:45 -0700, Dennis wrote:

> Hi, I have a
<snip />

Why are you cross-posting this to C and Perl newsgroups?


Rui Maciel

Posted by Kenny McCormack on June 18, 2008, 5:22 pm
Please log in for more thread options
>On Wed, 18 Jun 2008 12:33:45 -0700, Dennis wrote:
>
>> Hi, I have a
><snip />
>
>Why are you cross-posting this to C and Perl newsgroups?
>
>
>Rui Maciel

I assume because he is interested in a C/Perl solution to his problem.


Posted by Jürgen Exner on June 18, 2008, 8:25 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.

'perldoc perlop' and look for either tr/// in combination with the 'd'
option or s/// in combination with the 'g' option. Maybe in combination
with anchoring the RE.

Or you can use substr() to grab anything between the first and last
character, excluding both.

>2. extract out the hotmail addresses

perldoc -f grep

>and store it into another file.

perldoc -f open

>The hotmail addresses in the original file would be deleted.

perldoc -q "delete a line"

jue

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