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

所以 Diff 实用程序的工作方式就像我希望用于2个文件一样,但是我有一个项目需要一次比较2个以上的文件,也许一次比较多达10个。这也需要将所有这些文件并排放在一起。我的研究没有真正发现任何东西,维姆迪夫似乎是迄今为止最好的能力,比较4在同一时间。

我的问题是: 有没有什么实用工具可以一次比较两个以上的文件,或者有没有什么方法可以破解 diff/vimdiff 来进行多重比较?我将要比较的文件相对较短,所以不应该太慢。

先谢谢你!

58345 次浏览

Checkout "Beyond Compare": http://www.scootersoftware.com/

It lets you compare entire directories of files, and it looks like it runs on Linux too.

Vim can already do this:

vim -d file1 file2 file3

But you're normally limited to 4 files. You can change that by modifying a single line in Vim's source, however. The constant DB_COUNT defines the maximum number of diffed files, and it's defined towards the top of diff.c in versions 6.x and earlier, or about two thirds of the way down structs.h in versions 7.0 and up.

if your running multiple diff's based off one file you could probably try writing a script that has a for loop to run through each directory and run the diff. Although it wouldn't be side by side you could at least compare them quickly. hope that helped.

Displaying 10 files side-by-side and highlighting differences can be easily done with Diffuse. Simply specify all files on the command line like this:

diffuse 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt 10.txt

diff has built-in option --from-file and --to-file, which compares one operand to all others.

   --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.

Note: argument name --to-file is optional. e.g.

# 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

Not answering the main question, but here's something similar to what Benjamin Neil has suggested but diffing all files:

Store the filenames in an array, then loop over the combinations of size two and diff (or do whatever you want).

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

Derived from @charles-duffy's answer: https://stackoverflow.com/a/46719215/1160428

There is a simple an good way to do this = GREP.

Depending on the size of the text you can copy and paste it, or you can redirect the input of the file to the grep command. If you make a grep -vir /path to make a reverse search or a grep -ir /path. This is my way for certification exams.