LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How does "diff" only show differences? (https://www.linuxquestions.org/questions/linux-software-2/how-does-diff-only-show-differences-393488/)

daYz 12-16-2005 03:54 AM

How does "diff" only show differences?
 
Hi,

I am trying to compare two files with diff to see what the differences are between those two files. The problem I have with it is that the diff output shows both files instead off showing me the differences only. There are lines in the two files that are exactly the same but are shown in the output anyhow instead of leaving them away.

The way I use diff is:

Code:

diff filename filename
So does anyone know what command I should use to only show the differences between files?

Thanks.

Ben

Poetics 12-16-2005 05:26 AM

It could be that there's an extra bit of whitespace (spaces) at the end of the line, et cetera. Playing with the options may be of help -- the following are from the man page:

-b Ignore changes in amount of white space.
-B Ignore changes that just insert or delete blank lines.
-i Ignore changes in case; consider upper- and lower-case letters equivalent.
-I regexp Ignore changes that just insert or delete lines that match regexp.
--ignore-all-space Ignore white space when comparing lines.

daYz 12-16-2005 06:52 AM

Thanks for your help Poetics.

I have tried the different options (I have also combind them) you mention, except "-I", but they do not work. I have also checked the lines that correspond to each other, but there's no extra whitespace. They are exactly the same.

If I put the corresponding lines from the two files into two new files, diff does not show differences though.

I do not understand what the "-I" option does. Can you explain to me how I can apply this, and do your have other suggestions pherhaps?

Ben

stress_junkie 12-16-2005 07:34 AM

Maybe you have an alias for diff. Try the following.

alias diff

See if that clears things up.

dmartins 12-16-2005 10:56 AM

you could try gtkdiff. I've found it much easier to understand!

daYz 12-17-2005 01:11 AM

Quote:

Originally Posted by stress_junkie
Maybe you have an alias for diff. Try the following.

alias diff

See if that clears things up.

This does not seem the case. I get "not found" or something.

daYz 12-17-2005 01:18 AM

Quote:

Originally Posted by dmartins
you could try gtkdiff. I've found it much easier to understand!

Good Idea. I don't really mind which program I'll have to use as long as it works. I do not use X though, so what other programs can do what I want?

Other ideas on how to possibly solve this are still welcome of course.

Thanks,

Ben

bulliver 12-17-2005 03:10 AM

The lines diff are showing you are for context. The default is three lines before and after. If you use:
Code:

# diff -C0 file1 file2
then you will only see the different lines. "-U0" will also work if you prefer unified diff view. If you can't stand to see even diff's control lines then try:
Code:

# diff -C0 file1 file2 | grep -e "^\!"
Many output options are available if you look at "diff --help" or the man page.

daYz 12-17-2005 03:52 AM

Great! I have got it working now.

Everyone thanks for your help :)

Ben

daYz 01-04-2006 12:35 PM

Quote:

Originally Posted by daYz
Great! I have got it working now.

Actually, I was wrong.

I know now that the reason diff says the files differ is because the lines in the files are in a different order.
Besides the order everything is equal.

Does someone know with what command I can make the order of the lines equal?

bulliver 01-04-2006 02:27 PM

Quote:

Does someone know with what command I can make the order of the lines equal?
Running both files through 'sort' should do the trick if they are indeed same in all but line order...

daYz 01-05-2006 10:24 PM

Thanks bulliver. I will take a look at it.

Regards,

Ben


All times are GMT -5. The time now is 08:06 AM.