Match email address

If you have a file with several lines that contains email addresses that you like to extract, you can do that with Linux grep command:

File “emails.txt”:

somestreng anotherstring 342345 somename.lastname@domain.com

where somename.lastname@domain.com is the string you like to extract:

you can do this with:

grep -EiEio '\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b' emails.txt

Result:

somename.lastname@domain.com

Leave a Reply

Your email address will not be published. Required fields are marked *