12.21.2011

Grep All Email Addresses from a Text File Using Regular Expressions

Took me a while to construct this regular expression, thought it might be useful to someone else. grep -E -o "\b[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9.-]+\b" filename.txt NOTE: The above command should be on one line.
(You can also use egrep instead of grep with the -E switch)
egrep -o "\b[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9.-]+\b" filename.txt
From grep man pages:
-E = Interpret PATTERN as an extended regular expression.
-o = Show only the part of a matching line that matches PATTERN.

More info:
GREP MAN PAGE: http://ss64.com/bash/grep.html
GREP REGEX TUTORIAL: http://www.regular-expressions.info/grep.html

0 comments:

Post a Comment