Show me the email addresses in this file that aren’t in this other file…

I have two text files, each containing a list of email addresses.

The first file, invited.txt, has 82 email address of people who responded positively to my initial call for interest in the Crafting {:} a Life unconference back in February.

The second file, registered.txt, has 50 email addresses of people who’ve registered for the unconference.

I know that there are some people who responded to the initial call who haven’t registered, and I want to double-check with them to see if they’re planning to come (some of them likely thought that initial call for interest was registering).

How to get the list of email addresses in the first file that aren’t in the second file?

It turns out to be pretty easy from the Mac command line:

grep -i -v -f registered.txt invited.txt

The grep command is used to search inside files for things.

  • The -i flag says “ignore the case of the letters”. This way and will appear to be the same, which is what we want.
  • The -v flags kind of turns grep on its head, so that rather than searching for lines that match, we tell it to search for lines that don’t match.
  • The -f registered.txt says “take the lines from this file as the what you’re looking for,” except in this case, because of the -v, it’s the what we’re not looking for.
  • The invited.txt is the file we want to search.

Put that all together and what you get is “show me every email address in invited.txt that doesn’t appear in registered.txt.”

Or, in other words, “tell me who I invited who hasn’t registered.”


Peter Rukavina's picture
Peter Rukavina on April 29, 2019 - 13:54 Permalink

The Unix command line is like a mystical spell bag.