Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There are two files with list of names, one name per line. I need to find what names from the second list aren't in the first. Is there some clever way to do it using shell and not "real" programming language?

P.S. I did the comparison using Ruby, but still curious.

share|improve this question

Try this:

$ grep -vf file1 file2


$ comm -13 <(sort file1) <(sort file2)
share|improve this answer
For files of any appreciable size, you will find that your first option will suck in a spectacular fashion. Further, if the files are large and you might conceivably run this comparison more than once, you should sort the input into new files, rather than doing the sort every time you run comm. – Slartibartfast Sep 14 '11 at 4:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.