RSS Subscription
Linux Howtos & Tutorials

Enter your email:

Delivered by


NOTE:New tutorials are from LinuxCareer.com

Poll

Do you own or wish to have iPhone?
 


Linux eBooks FREE Download
A guide to programming Linux kernel modules
Introduction to Linux - A Hands on Guide
A Newbie's Getting Started Guide to Linux

Linux from Scratch - Create Your Own Linux System - Free eBook

Linux: The Hacking Solution (v.3.0)

SQLite 3 with PHP Essential Training – Free Video Training Tutorials

This guide will introduce you to the world of GNU/Linux

The GNU/Linux Advanced Administration

A Complete Beginner's Manual for Ubuntu 10.04 (Lucid Lynx)

Advanced Bash-Scripting Guide

Set up, maintain, and secure a small office email server

Partner Linux Sites:
How-To.LinuxCareer.com
Jobs.LinuxCareer.com
TuxMachines
Monsterb
LinuxBloggers
AdamsInfo
LinuxScrew
All For Linux

Extract email address from a text file

A following perl script and regular expression extracts all email addresses from an given text file. Sample text:

This perl script extracts all email addresses
from an given text file. This email address
is valid: web@email.net and this email address
is not valid web@email. Same as what_ever@public.com 
is a valid email address and address test@test. is 
not valid !

Regular expression to extract an email address using perl:

#!/usr/bin/perl

use strict;

my $email_count;

while (my $line = <>) { #read from file or STDIN
  foreach my $email (split /\s+/, $line) {
     if ( $email =~ /^[-\w.]+@([a-z0-9][a-z-0-9]+\.)+[a-z]{2,4}$/i ) {
 		print $email . "\n";
		$email_count++;
	
  }
}
}

print "Emails Extracted: $email_count\n";

Execution:

$ ./extract_email.pl emails.txt
web@email.net
what_ever@public.com
emails Extracted: 2

Share this linux post:

Submit Extract email address from a text file in Delicious Submit Extract email address from a text file in Digg Submit Extract email address from a text file in FaceBook Submit Extract email address from a text file in Google Bookmarks Submit Extract email address from a text file in Stumbleupon Submit Extract email address from a text file in Technorati Submit Extract email address from a text file in Twitter
 
Comments for this page are closed !!!
Please visit our new Linux Forum for additional help or discussion.


Linux eBooks FREE Download