Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Matching email address in a file surrounded by gunk

Status
Not open for further replies.

redshift

Technical User
Oct 30, 2002
7
US
Hi all:

I have a Netscape Mail address book from 6.x that for some reason will not export. The raw file contains all the email addresses I want to strip out, and each is preceeded by an "=" sign and followed by a ")" sign. I'm trying to come up with a good way to match anything between "=" and ")" that also contains "@" (meaning it is an email address) and print each email address found to a separate line.

Here is what I have so far:

#!/usr/bin/perl
$| = 1;

open (FILE, "ab.nab") || die("Could not read file!");
@lines = <FILE>;
close (FILE);

foreach $line (@lines) {
$_ = $line;

if (/\=(\.*\@\.*)\)/ig) {
$_ = $1;
}
print STDOUT $_ . &quot;\n&quot;;
}

For some reason it's definitely not working. Any ideas on why my matching string is bad?
 
Your pattern matching is looking for a literal '.' instead of the any character. In other words, don't escape (put a backslash) in front of '.'.

The line:
if (/\=(\.*\@\.*)\)/ig) {
should be:
if (/\=(.*\@.*)\)/ig) {

Also note that you don't need to keep setting $_ to other values. Instead of setting $_ = $line, you could just say:
if ($line =~ (/\=(.*\@.*)\)/ig) {
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top