Created
October 4, 2017 12:04
-
-
Save aduzsardi/f98fffafed8945de2c379d687bf82b44 to your computer and use it in GitHub Desktop.
grep match email address - print only matched substring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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