本文介绍了从两个文件中删除相似的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试找到一个 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'更多推荐
从两个文件中删除相似的行
发布评论