How to get all emails from the text with one command?
Sorry for my English! English is not my native language. One of the reasons to create this blog is to improve my English writing. So I will be highly obliged if you will help me with this. If you find a grammar error on this page, please select it with your mouse and press Ctrl+Enter.
I got an interesting problem today: there is a big text, in this text there many emails, need to get unique emails from this text, sort them and put in the file. It turned out that it is possible to do with one command. Here it is.
grep -E -o "\b[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9.-]+\b" file.txt | sort -n | uniq > emails.txt
The grep command gets all the emails from the text, then then they are sorted, left only unique and written to the file.
If all your data is located not in one file and you need to join all the file to one then there is another command:
cat file1 file2 file3 > file4
Love Linux :)