Skip to content

Instantly share code, notes, and snippets.

@aduzsardi
Created October 4, 2017 12:04
Show Gist options
  • Save aduzsardi/f98fffafed8945de2c379d687bf82b44 to your computer and use it in GitHub Desktop.
Save aduzsardi/f98fffafed8945de2c379d687bf82b44 to your computer and use it in GitHub Desktop.
grep match email address - print only matched substring
# Match email address from list of Name,Email , email can be with country code domain or company domain.
# List of names (file names.txt)
Cameron Carr [email protected]
Tim Burgess [email protected]
Wanda Dyer [email protected]
Bella Dowd [email protected]
Madeleine Mills [email protected]
grep -Eo '(\w+\.)?\w+@\w+\.[a-z]{2,3}$' names.txt
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
@aduzsardi
Copy link
Author

The same but with sed
sed -n -r 's/.*\s((\w+\.)?\w+@\w+\.[a-z]{2,3}$)/\1/p'

.*\s((\w+\.)?\w+@\w+\.[a-z]{2,3}$) - will actually match the whole line in this case and be replaced by the submatch ((\w+\.)?\w+@\w+\.[a-z]{2,3}$) represented by the back reference: \1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment