Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

I need to take two text files and check to see if a line that exists in File A doesn't exist anywhere in File B.

Each line in File A that does not exist in File B should be copied to an output log.

A friend of mine suggested SED but I've never used it before, so how would I go about doing this?

share|improve this question

It sounds like the lines are intended to be unique and order doesn't matter, so try this:

sort fileA > fileA.sort
sort fileB > fileB.sort
diff fileA.sort fileB.sort | sed -n "/^</{s/< //;p}"
share|improve this answer

Lines that only exist in fileA:

comm -23 <(sort fileA) <(sort fileB) > output.txt

All lines unique to fileA will be saved in the file output.txt.

share|improve this answer
Process substitution using the <(...) notation is an elegant solution. I thought about suggesting that form myself but it's only in bash, not the other shells, and it wasn't clear what shell the OP was using. – Nicole Hamilton Dec 2 '12 at 18:40

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.