我需要根据电子邮件地址从一个 csv (file-a) 中删除与另一个 csv (file-b) 中的字符串匹配或部分匹配的字符串:
文件-a
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
我在这里遇到了类似的问题:
但是,这只适用于完全匹配,我尝试使用“notmatch”而不是“notcontains”,但这不起作用。我对 powershell 很陌生,我不太清楚我需要做什么。任何帮助将不胜感激。
我首先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
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句