LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   diff question: how to show only missing files (https://www.linuxquestions.org/questions/linux-general-1/diff-question-how-to-show-only-missing-files-836534/)

chudster 10-06-2010 08:56 AM

diff question: how to show only missing files
 
I have a question on using diff. I have two files that contain directory/file listings: d11.lis and d11.lis from a previous day. I am not interested in files that changed, or were added, I just want to see a list of files that are missing on day two.

Any ideas?

Thanks in advance.

druuna 10-06-2010 09:03 AM

Hi,

I would use comm to do this and not diff.

Assuming both files are sorted: comm -23 file1 file2 will show entries that are missing in file2.

Hope this helps.

chudster 10-06-2010 09:19 AM

Quote:

Originally Posted by druuna (Post 4119437)
Hi,

I would use comm to do this and not diff.

Assuming both files are sorted: comm -23 file1 file2 will show entries that are missing in file2.

Hope this helps.

Awesome, thanks druuna!

druuna 10-06-2010 09:19 AM

You're welcome :)

chudster 10-07-2010 04:02 PM

Quote:

Originally Posted by druuna (Post 4119437)
Hi,

I would use comm to do this and not diff.

Assuming both files are sorted: comm -23 file1 file2 will show entries that are missing in file2.

Hope this helps.


Actually I think that just comm -3 file1 file2 is what shows entries missing in file2 (that's a -3, not a -23).

druuna 10-08-2010 01:29 AM

Hi,

Maybe it gives you the results you want, but it doesn't show files that are only missing from day 2 (file2) as stated in your first post.

1 - suppress lines unique to FILE1
2 - suppress lines unique to FILE2
3 - suppress lines that appear in both files

Examples:
Code:

# cat file1
0
1
A
B
W
X

$ cat file2
0
A
B
W
Z

$ comm -23 file1 file2
1
X

$ comm -3 file1 file2
1
X
        Z

As you can see, -23 shows 1 and X, which are missing in file2. -3 also shows Z, which is present in file2 but missing in file1.

Anyway, which of these you actually need depends on the actual requirements.

Hope this clears things up a bit.


All times are GMT -5. The time now is 01:05 AM.