unix diff side-to-side results?

删除回忆录丶 提交于 2019-12-29 11:41:29

问题


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

回答1:


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



回答2:


From icdiff's homepage:

Your terminal can display color, but most diff tools don't make good use of it. By highlighting changes, icdiff can show you the differences between similar files without getting in the way. This is especially helpful for identifying and understanding small changes within existing lines.

Instead of trying to be a diff replacement for all circumstances, the goal of icdiff is to be a tool you can reach for to get a better picture of what changed when it's not immediately obvious from diff.

IMHO, its output is much more readable than diff -y.




回答3:


diff -y --suppress-common-lines file1 file2



回答4:


You can use:

sdiff  file1 file2

or

diff -y file1 file2

or

vimdiff file1 file2

for side by side display.




回答5:


You should have sdiff for side-by-side merge of file differences. Take a read of man sdiff for the full story.




回答6:


You can simply use:

diff -y fileA.txt fileB.txt | colordiff

It shows the output splitted in two colums and colorized! (colordiff)




回答7:


Use the -y option:

diff -y file1 file2



回答8:


Try cdiff - View colored, incremental diff in workspace or from stdin with side by side and auto pager support.




回答9:


You can use vimdiff.

Example:

vimdiff file1 file2



回答10:


If your files have inconsistent use of spaces and tabs, you may find it helpful to include the -t argument to expand the tabs:

diff -ty file1 file2


来源:https://stackoverflow.com/questions/17195308/unix-diff-side-to-side-results

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!