Z
Z
Z-RoVeR2018-08-28 11:41:26
PowerShell
Z-RoVeR, 2018-08-28 11:41:26

How to use powershell to compare 2 csv files and write down the difference in the 3rd one?

There are 2 csv files with more than 3k lines. They have the same column structure, each has Name, Surname, Email, Phone, etc. columns.
I'm interested in comparing these files only by the Email column and writing non-duplicate lines in the 3rd (preferably with marking in which file this email is present and which is not.)
I danced with Compare-Object for a very long time, but did not achieve a result. Maybe faced with a similar problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
azarij, 2018-08-28
@Z-RoVeR

if(test-path c:\test\unique_emails.csv){remove-item c:\test\unique_emails.csv -force}
$1csv = Import-Csv C:\test\1.csv -Delimiter "`t"
$2 csv = Import-Csv C:\test\2.csv -Delimiter "`t"
foreach ($line in $1csv){if($2csv -notmatch $line.email){$line | export-csv -notypeinformation -delimiter "`t" -path c:\test\unique_emails.csv -Append}}
1.csv
name email phone
ak [email protected] 0123456
kb [email protected] 98543221
akk [email protected] com 0123456
kak [email protected] 98543221
aak [email protected]ak.com 0123456
kka [email protected] 98543221
aka [email protected] 0123456
kakk [email protected] 98543221
2.csv
name email phone
ak [email protected] 01234
kb [email protected] 98543221
akkk [email protected] 0123456
kakk [email protected] 98543221
aakk [email protected] 0123456
kkak [email protected] 98543221
akak [email protected] 0123456
kakkk [email protected] 98543221
in csv files are separated by tabs

F
forspamonly2, 2018-08-30
@forspamonly2

compare-object (Import-Csv 1.csv) (Import-Csv 2.csv) -Property "email" -PassThru

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question