Let's say I have two text files that I need to extract data out of. The text of the two files is as follows:
File 1:
1name - [email protected]
2Name - [email protected]
3Name - [email protected]
4Name - [email protected]
File 2:
email.com
email.com
email.com
anotherwebsite.com
File 2 is File 1's list of domain names, extracted from the email addresses. These are not the same domain names by any means, and are quite random.
How can I get the results of the domain names that match File 2 from File 1?
Thank you in advance!
Assuming that order does not matter,
grep -F -f FILE2 FILE1
should do the trick. (This works because of a little-known fact: the -F
option to grep
doesn't just mean "match this fixed string," it means "match any of these newline-separated fixed strings.")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With