powershell将比较2个csv文件,并在重复字段中更新行的其余部分

powershell将比较2个csv文件,并在重复字段中更新行的其余部分,powershell,csv,Powershell,Csv,这很难解释,但我会尽力的 我有两个CSV文件名为file1.CSV和file2.CSV 我希望file1.csv尝试将其第一列中的条目与file2.csv的第一列中的条目相匹配。如果存在匹配项,则我希望File1.csv中的行覆盖file2.csv中的特定行。我不介意它是否输出到另一个文件。请帮忙:) 文件1: uniqueID, first, surname, address 1, Joe, Bloggs, 32 Cheddar Rd 2, Bill, Gates, 21 SOmewhere

这很难解释,但我会尽力的

我有两个CSV文件名为file1.CSV和file2.CSV

我希望
file1.csv
尝试将其第一列中的条目与
file2.csv
的第一列中的条目相匹配。如果存在匹配项,则我希望File1.csv中的行覆盖
file2.csv中的特定行。我不介意它是否输出到另一个文件。请帮忙:)

文件1:

uniqueID, first, surname, address
1, Joe, Bloggs, 32 Cheddar Rd 
2, Bill, Gates, 21 SOmewhere Road
3, Tim, Burton, 24 This Lane
文件2:

uniqueID, first, surname, address
1, Joe, Bloggs, 34 BLAH BLAH
2, Bill, Gates, 43 BLAH BLAH
3, Tim, Burton, 65 BLAH BLAH
4, Kai, Peters, 42 BLAH BLAH
5, Gay, Thomas, 65 BLAH BLAH
输出:

uniqueID, first, surname, address
1, Joe, Bloggs, 32 Cheddar Rd 
2, Bill, Gates, 21 SOmewhere Road
3, Tim, Burton, 24 This Lane
4, Kai, Peters, 42 BLAH BLAH
5, Gay, Thomas, 65 BLAH BLAH
谢谢
Spencer

您应该展示一些您试图获得帮助的代码,但由于这是您的第一篇帖子,我将帮助您

$file1 = Import-Csv file1.txt
$file2 = Import-Csv file2.txt

$file2 | % {$Entry = $_; $file1 | ? {$_.uniqueID -eq $Entry.uniqueID} | % {$Entry.address = $_.address}}

$Results = @()

$file2  | % {$Results += New-Object -TypeName PSObject -Property @{"uniqueID" = $_.uniqueID; "first" = $_.First; "surname" = $_.surname; "address" = $_.address} }

$Results | Export-Csv -Path file3.csv -NoTypeInformation

到目前为止你试过什么吗?有什么特别的问题吗?