diff 命令的 Windows 等价物是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6877238/
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
What is the Windows equivalent of the diff command?
提问by wittythotha
I know that there is a post similar to this : here.
I tried using the comp
command like it mentioned, but if I have two files, one with data like "abcd" and the other with data "abcde", it just says the files are of different sizes. I wanted to know where exactly they differ. In Unix, the simple diff tells me which row and column, the comp command in windows works if I have something like "abd" and "abc". Not otherwise. Any ideas what I can use for this?
我知道有一个类似的帖子:here。
我尝试使用comp
它提到的命令,但是如果我有两个文件,一个带有像“abcd”这样的数据,另一个带有“abcde”这样的数据,它只是说文件的大小不同。我想知道他们到底有什么不同。在 Unix 中,简单的 diff 告诉我哪一行和哪一列,如果我有像“abd”和“abc”这样的东西,windows 中的 comp 命令可以工作。不是别的。有什么想法可以用于此目的吗?
回答by Andriy M
Run this in the CMD shell or batch file:
在 CMD shell 或批处理文件中运行:
FC file1 file2
FC
can also be used to compare binary files:
FC
也可用于比较二进制文件:
FC /B file1 file2
回答by David Heffernan
Well, on Windows I happily run diff
and many other of the GNU tools. You can do it with cygwin, but I personally prefer GnuWin32because it is a much lighter installation experience.
嗯,在 Windows 上我很高兴地运行diff
和许多其他 GNU 工具。您可以使用cygwin 来完成,但我个人更喜欢GnuWin32,因为它是一种更轻松的安装体验。
So, my answer is that the Windows equivalent of diff
, is none other than diff
itself!
所以,我的回答是,Windows 中的diff
, 就是diff
它本身!
回答by Robert Greiner
Winmerge has a command line utilitythat might be worth checking out.
Winmerge 有一个命令行实用程序,值得一试。
Also, you can use the graphical part of it too depending on what you need.
此外,您也可以根据需要使用它的图形部分。
回答by Tim Hutchison
Another alternative is to download and install git from here. Then, add the path to Git\bin\
to your PATH
variable. This will give you not only diff, but also many other linux commands that you can use from the windows command line.
另一种选择是从这里下载并安装 git 。然后,将路径添加Git\bin\
到您的PATH
变量。这不仅会为您提供 diff,还会为您提供可以从 Windows 命令行使用的许多其他 linux 命令。
You can set the PATH
variable by right clicking on Computer and selecting Properties. Then you can click on Advanced System Settings on the left side of the screen. In the pop up, click Environment Variables and then either add or update the PATH variable in your user variables with Git\bin\
您可以PATH
通过右键单击计算机并选择属性来设置变量。然后您可以单击屏幕左侧的高级系统设置。在弹出窗口中,单击环境变量,然后添加或更新用户变量中的 PATH 变量Git\bin\
回答by Nimish Choudhary
FC works great by in my case it was not helpful as I wanted just the lines that are changed. And FC give additional data like file name, same lines and bilateral comparison.
FC 在我的情况下效果很好,因为我只想要更改的行,所以它没有帮助。FC 提供额外的数据,如文件名、相同行和双边比较。
>fc data.txt data.txt.bak
***** DATA.TXT
####09
####09
####09
***** DATA.TXT.BAK
####09
####08
####09
but in my case I wanted only the lines that have changed and wanted those lines to be exported to different file, without any other header or data.
但在我的情况下,我只想要更改的行并希望将这些行导出到不同的文件,而没有任何其他标题或数据。
So I used "findstr"to compare the file :
所以我用“findstr”来比较文件:
findstr /V /G:data.txt.bak data.txt >DiffResult.txt
where :
在哪里 :
data.txt.bak
is the name of old file
data.txt.bak
是旧文件的名称
data.txt
is the name of new file
data.txt
是新文件的名称
DiffResult.txt
contains the data that is changed i.e just one line ####09
DiffResult.txt
包含更改的数据,即只有一行 ####09
回答by nerdfever.com
fc. fc is better at handling large files (> 4 GBytes) than Cygwin's diff.
FC fc 比 Cygwin 的 diff 更擅长处理大文件(> 4 GB)。
回答by Paul Williams
There's also Powershell (which is part of Windows). It ain't quick but it's flexible, here's the basic command. People have written various cmdlets and scripts for it if you need better formatting.
还有 Powershell(它是 Windows 的一部分)。它不快但很灵活,这是基本命令。如果您需要更好的格式,人们已经为它编写了各种 cmdlet 和脚本。
PS C:\Users\Troll> Compare-Object (gc $file1) (gc $file2)
Not part of Windows, but if you are a developer with Visual Studio, it comes with WinDiff (graphical)
不是 Windows 的一部分,但如果你是 Visual Studio 的开发人员,它带有 WinDiff(图形)
But my personal favorite is BeyondCompare, which costs $30.
但我个人最喜欢的是 BeyondCompare,售价 30 美元。
回答by proximace
The reason you getting the error with COMP is that the utility assumes the files that you are comparing are of the same size. To overcome that you can use th '/n'
option with which you can specify the number of lines you want to compare. (see the options supported by comp by typing 'comp /?'
on the command line.
so your command would look like :
COMP 出现错误的原因是该实用程序假定您正在比较的文件大小相同。为了克服这个问题,您可以使用 th'/n'
选项来指定要比较的行数。(通过'comp /?'
在命令行上键入来查看 comp 支持的选项。因此您的命令将如下所示:
C:\>comp "filepath1" "filepath2" /a /l /n=(the number of lines you want to compare) /c
This should solve your problem if you wanna stick to using COMP. But this will be a problem for really large files.
如果您想坚持使用 COMP,这应该可以解决您的问题。但是对于非常大的文件,这将是一个问题。
Though comp
is an option, but I feel it is primitive and FC
is a better option. you can use FORFILES
and FC
together to probably make a really good filecompare utility if you require one on a frequent basis.
虽然comp
是一个选择,但我觉得它很原始,FC
是一个更好的选择。如果您经常需要,您可以使用FORFILES
和FC
一起制作一个非常好的文件比较实用程序。
FC is used this way for ref:
FC 以这种方式用于 ref:
C:\>fc /c(case insensistive) /lbn(number of errors allowed before you wanna stop compare) /n(display line number) "filename1" "filename2"
there are many options available which you can see by 'fc /?'
hope this helps
有很多可用的选项,您可以看到'fc /?'
希望这会有所帮助
回答by mattkelly
回答by Ahmad
I've found a lightweight graphical software for windows that seems to be useful in lack of diff
command. It could solve all of my problems.
我发现了一个轻量级的 windows 图形软件,它在缺乏diff
命令时似乎很有用。它可以解决我所有的问题。