Computing.Net > Forums > Unix > grep emailaddresses from text file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

grep emailaddresses from text file

Reply to Message Icon

Name: AndrewG1976
Date: January 30, 2006 at 17:24:17 Pacific
OS: SunOS 5.8
CPU/Ram: 440Mhz/512MB
Comment:

Hi,

Say I have a text file (file1.txt) with the following contents:

"My emailaddress is address@domain.com"

I want to extract the emailaddress from the file and pipe this to another text file, I need the exact string without any spaces around it.

So for example "address@domain.com" is written to another file (file2.txt).

How can I do this?

Thanks!



Sponsored Link
Ads by Google

Response Number 1
Name: Krispy
Date: February 2, 2006 at 00:01:46 Pacific
Reply:

Do all the lines in file1.txt being with:

"My emailaddress is "


0

Response Number 2
Name: AndrewG1976
Date: February 2, 2006 at 22:14:52 Pacific
Reply:

No. There could be any text before the email address.


0

Response Number 3
Name: FishMonger
Date: February 4, 2006 at 08:13:45 Pacific
Reply:

#!/usr/bin/perl -w

use strict;
use Email::Find;

open (SRC, "source.txt") || die "can't open source file $!";
open (DEST, ">desination.txt") || die "can't open destination file $!";

my $finder = Email::Find->new(sub { my($email, $orig_email) = @_;
print DEST $email->format,$/;
return $orig_email;
});

while(my $text = <SRC>) { $finder->find(\$text); }

close SRC;
close DEST;



0

Response Number 4
Name: AndrewG1976
Date: February 12, 2006 at 16:38:58 Pacific
Reply:

Sorry I'm not a Unix guru, how do I run the script?

All I did was save the script as 'emailgrep' and change the 'SRC' filename:

/export/home/user>more emailgrep
#!/usr/bin/perl -w
use strict;
use Email::Find;

open (SRC, "Export2.TXT") || die "can't open source file $!";
open (DEST, ">desination.txt") || die "can't open destination file $!";

my $finder = Email::Find->new(sub { my($email, $orig_email) = @_;
print DEST $email->format,$/;
return $orig_email;
});

while(my $text = <SRC>) { $finder->find(\$text); }

close SRC;
close DEST;

/export/home/user>emailgrep
Can't locate Email/Find.pm in @INC (@INC contains: /usr/perl5/5.6.1/lib/sun4-sol
aris-64int /usr/perl5/5.6.1/lib /usr/perl5/site_perl/5.6.1/sun4-solaris-64int /u
sr/perl5/site_perl/5.6.1 /usr/perl5/site_perl /usr/perl5/vendor_perl/5.6.1/sun4-
solaris-64int /usr/perl5/vendor_perl/5.6.1 /usr/perl5/vendor_perl .) at emailgre
p line 3.
BEGIN failed--compilation aborted at emailgrep line 3.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: grep emailaddresses from text file

script to combine data from 2 files www.computing.net/answers/unix/script-to-combine-data-from-2-files/8101.html

unix text file parser www.computing.net/answers/unix/unix-text-file-parser/5430.html

Remove blanks from a text file www.computing.net/answers/unix/remove-blanks-from-a-text-file/6582.html