代码之家  ›  专栏  ›  技术社区  ›  Javed Ahamed

DIFF实用程序适用于2个文件。如何一次比较两个以上的文件?

  •  68
  • Javed Ahamed  · 技术社区  · 17 年前

    我的问题是:是否有任何实用程序可以一次比较两个以上的文件,或者有一种方法可以破解diff/vimdiff,从而可以进行多次比较?我将要比较的文件相对较短,所以不应该太慢。

    4 回复  |  直到 16 年前
        1
  •  112
  •   Derrick Moser Derrick Moser    17 年前

    Diffuse . 只需在命令行中指定所有文件,如下所示:

    漫反射1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt 10.txt

        2
  •  33
  •   Noah Medling    17 年前

    Vim已经可以做到这一点:

    vim -d file1 file2 file3
    

    但是你通常被限制为4个文件。然而,您可以通过修改Vim源代码中的一行来改变这一点。常数 DB_COUNT 差异 编辑文件,并且它的定义朝向 diff.c 在版本6.x和更早的版本中,或大约三分之二的版本中 structs.h 在7.0及更高版本中。

        3
  •  12
  •   Mark Chackerian    5 年前

    diff --from-file --to-file ,它将一个操作数与所有其他操作数进行比较。

       --from-file=FILE1
              Compare FILE1 to all operands.  FILE1 can be a directory.
    
       --to-file=FILE2
              Compare all operands to FILE2.  FILE2 can be a directory.
    

    注意:参数名 --归档 是可选的。 例如

    # this will compare foo with bar, then foo with baz .html files
    $ diff  --from-file foo.html bar.html baz.html
    
    # this will compare src/base-main.js with all .js files in git repo,
    # that has 'main' in their filename or path
    $ git ls-files :/*main*.js | xargs diff -u --from-file src/base-main.js
    
        4
  •  1
  •   Scott Anderson    17 年前

    结帐“无与伦比”: http://www.scootersoftware.com/

    它可以让你比较文件的整个目录,看起来它也在Linux上运行。

        5
  •  1
  •   Benjamin Neil    17 年前

    如果您基于一个文件运行多个diff,您可能会尝试编写一个脚本,该脚本有一个for循环来运行每个目录并运行diff。尽管它不会并排运行,但您至少可以快速比较它们。希望这有帮助。

        6
  •  0
  •   anask    6 年前

    没有回答主要问题,但这里有一些类似于 what Benjamin Neil has suggested 但是 差异 正在删除所有文件:

    将文件名存储在一个数组中,然后循环大小2和diff的组合(或者执行任何您想要的操作)。

    files=($(ls -d /path/of/files/some-prefix.*))     # Array of files to compare
    max=${#files[@]}                                  # Take the length of that array
    for ((idxA=0; idxA<max; idxA++)); do              # iterate idxA from 0 to length
      for ((idxB=idxA + 1; idxB<max; idxB++)); do     # iterate idxB + 1 from idxA to length
        echo "A: ${files[$idxA]}; B: ${files[$idxB]}" # Do whatever you're here for.
      done
    done
    

    源自 @charles-duffy 主席的答复: https://stackoverflow.com/a/46719215/1160428

        7
  •  -1
  •   CertainPerformance    5 年前

    有一个简单的好方法来实现这一点=GREP。

    根据文本的大小,您可以复制和粘贴文本,也可以将文件的输入重定向到grep命令。如果您使用grep-vir/path进行反向搜索,或者使用grep-ir/path。这是我参加认证考试的方式。

    推荐文章