从两个文件中删除相似的行 [英] Removing similar lines from two files
本文介绍了从两个文件中删除相似的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试找到一个 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.com
google.com
stackoverflow.com
facebook.com
twitter.com
文件 B
stackoverflow.com
facebook.com
比较后:文件 A
yahoo.com
google.com
twitter.com
推荐答案
您可以使用以下方式从文件 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'
这篇关于从两个文件中删除相似的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文