bash unix diff 左右结果?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17195308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 23:51:03  来源:igfitidea点击:

unix diff side-to-side results?

bashunixdiff

提问by 719016

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:

如何并排绘制 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

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

回答by fedorqui 'SO stop harming'

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

man diff,您可以使用-y并排操作。

-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

回答by timmfin

From icdiff's homepage:

从icdiff的主页

enter image description here

在此处输入图片说明

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.

您的终端可以显示颜色,但大多数差异工具并没有很好地利用它。通过突出显示更改,icdiff 可以向您显示相似文件之间的差异而不会妨碍您。这对于识别和理解现有生产线中的微小变化特别有用。

icdiff 的目标不是试图成为所有情况下的 diff 替代品,而是成为一个工具,您可以使用它来更好地了解在 diff 中发生的变化不是很明显。

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

恕我直言,它的输出比diff -y.

回答by Rjazhenka

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

回答by srpatch

You can use:

您可以使用:

sdiff  file1 file2

or

或者

diff -y file1 file2

or

或者

vimdiff file1 file2

for side by side display.

用于并排显示。

回答by Chris Seymour

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

您应该sdiff并行合并文件差异。阅读man sdiff全文。

回答by Jorge Fernando Matricali

You can simply use:

您可以简单地使用:

diff -y fileA.txt fileB.txt | colordiff

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

它显示了分成两列并着色的输出!( colordiff)

回答by ymattw

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

尝试cdiff- 在工作区或从标准输入查看彩色增量差异,并排和自动寻呼机支持。

回答by rectummelancolique

Use the -yoption:

使用-y选项:

diff -y file1 file2

回答by Eduardo Cuomo

You can use vimdiff.

您可以使用vimdiff.

Example:

例子:

vimdiff file1 file2

回答by Bucket

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

如果您的文件对空格和制表符的使用不一致,您可能会发现包含-t扩展制表符的参数很有帮助:

diff -ty file1 file2