我正在尝试找到一个 PowerShell 解决方案,以从文件 A 中删除与文件 B 中相似的行.Compare-Object $A $B 进行比较,但如何删除项目?
I'm trying to find a PowerShell solution to remove lines from file A that are similar in File B. Compare-Object $A $B does the comparing, but how to I go about deleting the items?
文件 A
yahoo google stackoverflow facebook twitter文件 B
stackoverflow facebook比较后:文件 A
yahoo google twitter 推荐答案您可以使用以下方式从文件 A 中删除文件 B 的内容:
You can remove the contents of file B from file A with something like this:
$ref = Get-Content 'C:\path\to\fileB.txt' (Get-Content 'C:\path\to\fileA.txt') | ? { $ref -notcontains $_ } | Set-Content 'C:\path\to\fileA.txt'