LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-16-2005, 03:54 AM   #1
daYz
Member
 
Registered: Nov 2003
Distribution: Ubuntu
Posts: 164

Rep: Reputation: 30
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
 
Old 12-16-2005, 05:26 AM   #2
Poetics
Senior Member
 
Registered: Jun 2003
Location: California
Distribution: Slackware
Posts: 1,181

Rep: Reputation: 49
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.
 
Old 12-16-2005, 06:52 AM   #3
daYz
Member
 
Registered: Nov 2003
Distribution: Ubuntu
Posts: 164

Original Poster
Rep: Reputation: 30
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
 
Old 12-16-2005, 07:34 AM   #4
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Maybe you have an alias for diff. Try the following.

alias diff

See if that clears things up.
 
Old 12-16-2005, 10:56 AM   #5
dmartins
Member
 
Registered: Oct 2005
Location: Ontario, Canada
Distribution: Arch, Gentoo
Posts: 98

Rep: Reputation: 15
you could try gtkdiff. I've found it much easier to understand!
 
Old 12-17-2005, 01:11 AM   #6
daYz
Member
 
Registered: Nov 2003
Distribution: Ubuntu
Posts: 164

Original Poster
Rep: Reputation: 30
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.
 
Old 12-17-2005, 01:18 AM   #7
daYz
Member
 
Registered: Nov 2003
Distribution: Ubuntu
Posts: 164

Original Poster
Rep: Reputation: 30
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
 
Old 12-17-2005, 03:10 AM   #8
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
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.
 
Old 12-17-2005, 03:52 AM   #9
daYz
Member
 
Registered: Nov 2003
Distribution: Ubuntu
Posts: 164

Original Poster
Rep: Reputation: 30
Great! I have got it working now.

Everyone thanks for your help

Ben
 
Old 01-04-2006, 12:35 PM   #10
daYz
Member
 
Registered: Nov 2003
Distribution: Ubuntu
Posts: 164

Original Poster
Rep: Reputation: 30
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?
 
Old 01-04-2006, 02:27 PM   #11
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
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...
 
Old 01-05-2006, 10:24 PM   #12
daYz
Member
 
Registered: Nov 2003
Distribution: Ubuntu
Posts: 164

Original Poster
Rep: Reputation: 30
Thanks bulliver. I will take a look at it.

Regards,

Ben
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
Differences between the "free" and "paid" versions eraser Linux - General 4 11-18-2015 06:30 PM
Utterly fascinating boot sector problem: "Differences: (offset:original/backup)" Bert Linux - Software 4 07-01-2013 05:29 PM
Kernel RPM "diff" update patches. redarrow Fedora 2 10-22-2005 01:52 AM
Differences of "make" in Kdev and cmd line srisner Linux - Software 1 12-23-2004 09:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration