Linux – Compare two files and output the differences

bashcommand linediff()linuxunix

I am aware of diff and using loops but I just cant seem to really get what I need with diff. I'm basically looking to compare two files (file2.txt and file2.txt) and just get the output of what is missing between them.

Objective 1: Find what is missing in file2.txt from file1.txt

Objective 2: Find what is missing in either file. Some lines may exist in file2.txt that arent in file1.txt. I'd like to know about them as well.

diff only tells me that the two files arent the same, going line by line comparing the differences. What I need is a program that goes through the file, and doesn't discriminate by lines. If a line containing '/bin/mount' is found on line 2 of file1.txt and is found on line 59 of file2.txt, then I don't need to know about it. I only want to know what isn't there as a whole. Can this be done?

Best Answer

If you don't care about the line order, sort the files first. To see what lines are missing in what file, use comm instead of diff:

comm <(sort file1) <(sort file2)
Related Question