Skip to content
Advertisement

Finding emails from one file in another

I want to find emails from one file listed as such:

JavaScript

in another file listed as so:

JavaScript

and output the lines from the second file that match with the first file also keeping in mind it needs to match the entire email from start to finish so it won’t match robertjohn@blogs.com accidently.

Desired output:

JavaScript

Thanks!

Advertisement

Answer

With grep, get the newline separated patterns (strings here, -F) from an input file with -f, and match with the other file:

JavaScript

With awk, keeping an array with emails as indexes and checking if the first field of each record in the second file is an index:

JavaScript

Example:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement