如何在powershell中比较并输出两个文件的相似度?

问题描述 投票:0回答:1

我需要在powershell中比较两个文件,找到两者之间的相似之处并输出。

例如

a.txt:

words are easy to understand

buses drive very fast

john had to go and work hard

b.txt:

buses drive very slow

words are not always easy to understand

stack overflow is great

I worked hard yesterday.

所以它应该给我的输出是:

words

understand

buses

john

hard

etc.

它不应该比较行,而应该比较整个文本中的常见单词/字符串。

谢谢,

我尝试使用

compare-Object
,但我可能会以一种逐行比较txt文件的方式使用它,我希望它读取两个文件上的整个文档并打印在其中找到的单词或字符串两者都有。

powershell scripting
1个回答
0
投票

你可以使用 git 文件哈希:

$file1Hash = Get-FileHash -Path $file1Path $file2Hash = Get-FileHash -Path $file2Path

if ($file1Hash.Hash -eq $file2Hash.Hash) { 写入输出“文件相同” } 别的 { 写入输出“文件不同” }

© www.soinside.com 2019 - 2024. All rights reserved.