non*_*ity 6 windows-7 powershell diff comparison
Windows 7 上的 Powershell 可以区分硬盘驱动器上的两个文件吗?
有时文本比较是有帮助的,但除此之外,仅仅判断一个文件是否与另一个文件相同是有帮助的。谢谢。
更新:
在 UNIX 上,它是
diff file1.dat file2.dat
Run Code Online (Sandbox Code Playgroud)
在 Powershell 上,如果我创建包含内容“hello”的 file1.txt 并将此文件复制到 file2.txt,然后键入
diff file1.txt file2.txt
Run Code Online (Sandbox Code Playgroud)
结果是
InputObject SideIndicator
----------- -------------
file2.txt =>
file1.txt <=
Run Code Online (Sandbox Code Playgroud)
如果我将 file2.txt 的内容更改为“hello world”并再次进行 diff,则 diff'ing 的结果是相同的。
编辑:显然有一个内置别名所以这也有效:
diff $(Get-Content C:\file1.txt) $(Get-Content C:\file2.txt)
Run Code Online (Sandbox Code Playgroud)
你可以这样做:
Compare-Object $(Get-Content c:\file1.txt) $(Get-Content c:\file2.txt)
Run Code Online (Sandbox Code Playgroud)
这是一些示例输出:
InputObject SideIndicator
----------- -------------
This is a line in file 2 =>
This is a line in file 1 <=
Run Code Online (Sandbox Code Playgroud)
您还可以执行 -excludeDifferent 以仅显示相同的行或执行 -includeEqual 以包含相同的行。
| 归档时间: |
|
| 查看次数: |
8083 次 |
| 最近记录: |