最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

从两个文件中删除相似的行

SEO心得admin80浏览0评论
本文介绍了从两个文件中删除相似的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试找到一个 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'
发布评论

评论列表(0)

  1. 暂无评论