Linux – Substract contents of one textfile from contents of another textfile on Linux

bashlinuxvim

I have two text files on Linux. One contains a list of valid IDs. E.g:

abcd
efgh
ijkl
etc.

The other contains a list of invalid IDs. But, some of these also appear on the list of valid IDs, in this example "efgh":

mnop
qrst
efgh
etc.

How can I easily construct a text file that contains all the lines from the invalid list that do not appear in the valid list? That is, I want to end up with a text file that has:

mnop
qrst
etc.

I'd like either some Linux commandline magic of some clever Vim trickery. Thanks in advance!

Best Answer

I think comm can help you do what you want.

It is a less known command line tool that shall be present in most Linux systems.

Related Question