Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unix diff side-to-side results?

Tags:

bash

unix

diff

How can I plot the results of a unix diff command side-to-side instead of one difference after the other? See below for an example:

    diff /tmp/test1  /tmp/test2 1,4c1,2 < asfdsadf < asdfsad < fsaf < fdsadf --- > asdfsafdsf > saf 6,8d3 < sadf < asdf < sadf 10d4 < fasd 12,13c6,14 < sadfa < fd --- > sadf > sadf > sadf > sadf > sadf > sadf > sadf > sadf > safa 

I would like to have something like:

diff /tmp/test1  /tmp/test2 1,4c1,2 < asfdsadf       > asdfsafdsf < asdfsad        > saf        < fsaf < fdsadf --- 6,8d3 < sadf < asdf < sadf 10d4 < fasd 12,13c6,14 < sadfa               > sadf < fd              > sadf ---               > sadf               > sadf               > sadf               > sadf               > sadf               > sadf               > safa 
like image 908
719016 Avatar asked Jun 19 '13 15:06

719016


People also ask

What is the difference between diff and Sdiff?

If you want to compare two files, and display the differences, you can use the diff , the sdiff or vimdiff command. The diff will display the differences between two files. While the sdiff command will display the differences with file1 on the left and file2 on the right.

How does Unix diff command work?

On Unix-like operating systems, the diff command analyzes two files and prints the lines that are different. In essence, it outputs a set of instructions for how to change one file to make it identical to the second file.


1 Answers

From man diff, you can use -y to do side-by-side.

-y, --side-by-side        output in two columns 

Hence, say:

diff -y /tmp/test1  /tmp/test2 

Test

$ cat a                $ cat b hello                  hello my name                my name is me                  is you 

Let's compare them:

$ diff -y a b hello                                                           hello my name                                                         my name is me                                                         | is you 
like image 179
fedorqui 'SO stop harming' Avatar answered Oct 09 '22 08:10

fedorqui 'SO stop harming'