ellsusan ellsusan - 2 months ago 7
Linux Question

Using grep to check for proper formatting of an email address

Using grep

I'm trying to check every line of a file and see if it has the proper formatting for an email address.

I'm looking for email addresses in the format of

xxxxx@gmail.com

I'm not concerned about the user ID. What I want to check is that the domain does not have invalid characters such as an underscore _ in it and count them.

Checking if it has a @ in it

grep -c "@" testing.txt


What I want to do now is, if it has the @ symbol. It should look to see if it has an invalid character

_


in its domain. (not the .com/.edu etc parts)

I also want to check if there is a period after the @ symbol.

testing.txt

tyler1
Tanktop_Paedo
xyz2@geocities.com
milt@uole.com
justincrump
cranges10
namer@uole.com
soulfunkbrotha
hotbooby@geocities.com
Fire_Crazy
dingbat@geocities.com
crazyrabit@geo_cat.com
panther@_cities.com


expected output

crazyrabit@geo_cat.com
panther@_cities.com

Answer
grep '@.*_' testing.txt

Output:

crazyrabit@geo_cat.com
panther@_cities.com
Comments