Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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!

#!/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;

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.

![]() |
![]() |
![]() |

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