Number of differences between 2 files | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Number of differences between 2 files

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-01-2003
sharuvman sharuvman is offline
Registered User
 
Join Date: Mar 2002
Last Activity: 8 December 2004, 1:38 AM EST
Location: Bangalore,Karnataka State,India
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Network Number of differences between 2 files

Hi,

"diff" command takes two file names as arguements and gives the difference between the two.

How do I get the number of differences between two files ???
(Excluding whitespaces).
Don't ask me to count number of lines produced by "diff".

Thanks in advance,
Sharath
Sponsored Links
    #2  
Old 09-01-2003
cerberusofhnsg's Avatar
cerberusofhnsg cerberusofhnsg is offline
Registered User
 
Join Date: Jul 2003
Last Activity: 25 October 2003, 11:41 PM EDT
Location: MT
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
diff file1 file2|wc -l
will give you what you want, right?
Sponsored Links
    #3  
Old 09-01-2003
google's Avatar
google google is offline Forum Advisor  
Advisor
 
Join Date: Jul 2002
Last Activity: 17 June 2009, 5:17 PM EDT
Location: Atlanta
Posts: 740
Thanks: 0
Thanked 2 Times in 2 Posts
Quote:
diff file1 file2|wc -l
wc -l would simply count all of the differences found in file 1 + file 2. Be sure to use either the -b or the -w flag to ignore whitespace, tabs and other characters. To get a better picture of the comparison using diff, pipe the output to grep and grep for the lines with a '<' or '>' symbol. That way, you will get lines that are different in file 1 or file 2.

If you are working with data files that can be sorted, look at using the comm command. You may also look at using cmp to do a comparison.

As always, see:

man diff
or
man cmp
or
man comm

Last edited by google; 09-01-2003 at 06:59 PM..
    #4  
Old 09-01-2003
cerberusofhnsg's Avatar
cerberusofhnsg cerberusofhnsg is offline
Registered User
 
Join Date: Jul 2003
Last Activity: 25 October 2003, 11:41 PM EDT
Location: MT
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
sorry about that, read your post wrong. wc -l will not ignore whitespace.
Sponsored Links
    #5  
Old 09-03-2003
criglerj's Avatar
criglerj criglerj is offline
Registered User
 
Join Date: May 2002
Last Activity: 7 September 2008, 10:24 PM EDT
Location: Atlanta
Posts: 129
Thanks: 0
Thanked 0 Times in 0 Posts
It's unclear what you mean by "number of changes". Number of changed lines? Number of changed characters? Number of changed regions?

Assuming the last of those (number of changed regions), one approach is to understand the output of diff. In Solaris diff (and most others, as I recall) the only lines that start with digits are the lines that specify the changed regions. so you can do this:

Code:
diff filea fileb | grep '^[1-9]' | wc -l

or

Code:
diff filea fileb | awk '/^[1-9]/ {i++} END {print i}'

But in either of these, you are at the mercy of diff, which may not have the same idea about what a "region" is as you do. With more modern diffs than I have at hand, e.g., gnu diff, you have a lot more options to control what diff shows as a difference region.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Finding differences between 2 text files OBAFGKM UNIX for Dummies Questions & Answers 6 11-06-2010 07:01 AM
Differences between 2 Flat Files and process the differences newbie_8398 Shell Programming and Scripting 5 07-17-2010 01:31 PM
Eliminating differences in two files selmar Shell Programming and Scripting 5 07-13-2010 10:46 AM
Detect differences in two files pxy2d1 Shell Programming and Scripting 4 07-07-2010 08:42 AM
Differences between jar files runnerpaul Solaris 3 10-20-2008 04:18 PM



All times are GMT -4. The time now is 04:50 AM.