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

编程入门 行业动态 更新时间:2024-10-13 22:25:59
本文介绍了从两个文件中删除相似的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

更多推荐

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

本文发布于:2023-11-30 16:55:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650779.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两个   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!