tags:

views:

66

answers:

2

What is a good method for using diff to show a percentage difference between two files?

Such as if a file has 100 lines and a copy has 15 lines that have been changed the diff-percent would be 15%.

+1  A: 

Something like this perhaps?

Two files, A1 and A2.

$ sdiff -B -b -s A1 A2 | wc would give you how many lines differed. wc gives total, just divide.

The -b and -B are to ignore blanks and blank lines, and -s says to suppress the common lines.

MJB
from man file of wc: newlines, words, and bytes.you divide the first number in the output by the number of lines in the file are you comparing. wc -l, gives you only number of lines and can be added to the command above. -- Response to AlligatorJack
cdated
@cdated : thanks for clarifying. I did not see the question/response of course until you commented.
MJB
A: 

Hello. I just tried the line postet by MKB (sdiff -B - b - s A1 A2 | wc) and I get three numbers as a result:

51, 436 and 3133 (in this order)

what do they mean? Which is which? Thanks! :)

AlligatorJack
this should probably be in MJB answer's comment. I placed my explanation there.
cdated