I have a file (testdata.txt) with many email addresses and random text. Using the grep command:
I want to make sure they are email addresses and not text, so I want to filter them out so that only lines with "@" are included.
I also want to filter them out so that only email addresses that start with the letter A-M or a-m are shown and have a period separating the first name and last name.
Eg. john.doe@gmail.com However, johndoe@gmail.com would be included.
Lastly, I want to get the count of all the email addresses that follow these rules.
So far I've only been able to make sure they are email addresses by doing
grep -c "@" testdata.txt
.
Using the grep cmd I also want to check how many email addresses have a government domain ("gov").
I wanted to do a check that it has a @ sign in the line and that it also contains gov. However, I don't get the answer I want when I do any of the following.
grep -c "@\|gov" testdata.txt I get the amount of lines that have a @ not @ and gov
grep -c "@/|gov" testdata.txt I get 0
grep -c "@|gov" testdata.txt I get 0