使用另一个csv从csv中删除类似的字符串

问题描述 投票:0回答:1

我需要根据电子邮件地址从一个csv(file-a)中删除与另一个csv(file-b)中的字符串匹配或部分匹配的字符串:

文件一

email,Firstname,Lastname 
[email protected],pete,Smith
[email protected],paul,
[email protected],,Jones
[email protected],puff,Dragon

文件-B

email,Firstname,Lastname
[email protected],,Smith
[email protected],Mary

重复数据删除输出文件

email,Firstname,Lastname 
[email protected],paul,
[email protected],puff,Dragon

我在这里遇到了类似的问题:

Removing similar lines from two files

但是,这仅适用于完全匹配,我尝试使用“notmatch”而不是“notcontains”,但这不起作用。我对powershell很新,我无法弄清楚我需要做什么。任何帮助将不胜感激。

powershell csv string-comparison
1个回答
0
投票

我首先Import-Csv文件和使用Compare-Object限制属性email

## Q:\Test\2019\02\28\SO_54929339.ps1

$fileA = Import-csv '.\file-a.csv'
$fileB = Import-csv '.\file-b.csv'

$deduped = Compare-Object -Ref $fileA -Diff $fileB -Property email -PassThru | 
  Where-Object Sideindicator -eq '<=' | 
    Select-Object * -ExcludeProperty Sideindicator

$deduped 
$deduped | Export-Csv '.\deduped-output-file.csv' -NoTypeInformation

样本输出:

> Q:\Test\2019\02\28\SO_54929339.ps1

email          Firstname Lastname
-----          --------- ---------
[email protected] paul
[email protected] puff      Dragon
© www.soinside.com 2019 - 2024. All rights reserved.