In linux/unix, you can use bash diff
, using system()
in matlab. (related article)
It goes like this:
[content_differs, printout] = system('diff --side-by-side --left-column file1 file2');
content_differs
is 0 if file1 and file2 have the same content, printout
is a string. You can access its the data line-by-line (you can use split in matlab or pipe other commands).
'
The differences can be parsed according to the character in the middle. As I have observed, "(" means no difference for some reason. "<", ">" and "|" refer to additions and changed lines.
(You have soo many options with diff to display common content too -- check out this link for details)
UPDATE:
A simple parsing script for your file which displays all the common parts.
file1 = 'your_file.m'
file2 = 'your_other_file.m';
[is_diff,output] = system(['diff --side-by-side --left-column ',file1,' ',file2]);
lines = regexp(output, '\n', 'split');
for i=1:(length(lines)-1)
line = lines{i};
if line(end) == '(' % common part
disp( line(1:(end-1)) );
end
end