如何才能并排绘制unix diff命令的结果,而不是一个接一个地显示差异?参见以下示例:

    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

我想要类似的东西:
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

最佳答案

man diff中,您可以使用-y并排执行。

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

因此,说:
diff -y /tmp/test1  /tmp/test2

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

让我们比较一下:
$ diff -y a b
hello                                                           hello
my name                                                         my name
is me                                                         | is you

10-06 05:10