I have two SQL files, one is old.sql and the other one is new.sql.

Suppose old.sql contains a table with three fields, Emp_Id, Name and Address and data stored in old.sql as follows:

Insert into table1 values (101 ,"a", "xyz");
Insert into table1 values (102 ,"b", "pqr");

Then I have changed "a" address "xyz" to "xyz123" and saved that data in the new.sql file. Now the new.sql file contains data as follows:

Insert into table1 values (101 ,"a", "xyz123");
Insert into table1 values (102 ,"b", "pqr");

When I use the diff command like this:

diff old.sql new.sql

it gives differences line-wise but I want only updated data, like xyz123.

share|improve this question

You might find wdiff useful for this type of comparison; it's a front-end to diff which produces word-by-word comparisons. With your example it produces by default

Insert into table1 values (101 ,"a", [-"xyz");-] {+"xyz123");+}
Insert into table1 values (102 ,"b", "pqr");

It can use terminal features to make the output more legible on a terminal (wdiff -t). It also has a -3 option which limits output to changed words only:

======================================================================
 [-"xyz");-] {+"xyz123");+}
======================================================================
share|improve this answer
    
but when I use wdiff command instead of diff command prompt is showing error wdiff command not found – user168519 Jun 2 '16 at 12:16
    
@user168519 that simply means you need to install it, sudo apt-get install wdiff or sudo dnf install wdiff or sudo yum install wdiff or your local equivalent. – Stephen Kitt Jun 2 '16 at 12:21
    
Hi Stephen, I have installed wdiff but it is not comparing data present inside the parenthesis. – user168519 Jun 2 '16 at 13:35
    
@user168519 that's odd, could you edit your question to show wdiff's behaviour? – Stephen Kitt Jun 2 '16 at 13:58
    
Okay I will edit my question, Thanks. – user168519 Jun 3 '16 at 5:36

By definition, diff is showing differences lines by lines (see diff manual page), it will therefore not show only the differing characters. You can reduce the amount of difference by pre-processing the files, for exemple by inserting an end-of-line character after each semi-column:

sed -e 's/;/;\'$'\n/g' old.sql > old.patched

Then use diff on the two resulting files.

share|improve this answer

You can use:

diff -u old.sql new.sql |colordiff |diff-highlight

screenshot

colordiff is a Ubuntu package. You can install it using sudo apt-get install colordiff.

diff-hight is from git (since version 2.9). It is located in /usr/share/doc/git/contrib/diff-highlight/diff-highlight. You can put it somewhere in your $PATH. Or get it from diff-so-fancy project.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.