I have 2 CSV’s. Below is just an excerpt of each so I can show how they are formatted. I would like to match the surname and givenname from SOURCE to CHANGE, and if there is a match grab the “emailaddress” from the CHANGE CSV and place it into a new column in the SOURCE CSV.
SOURCE CSV
"Employee ID","username","givenname","surname","emailaddress","title","Division","Location" "204264","ABDUL.JALIL@domain.com","Abdul Jalil","Bin Hajar","Abdul.jalil@domain.com","Warehouse Associate I","Singapore","Singapore, " "30053","ABEL.BARRAGAN@domain.com","Abel","Barragan","Abel.Barragan@domain.com","Manager, Customer Programs - CMS","Germany","Norderstedt, "
CHANGE CSV
givenname,surname,samaccountname,emailaddress,mail,country,city,state Abigai,Teoyotl Rugerio,Abigai.Teoyotl,Abigai.TeoyotlRugerio@domain.com,Abigai.TeoyotlRugerio@domain.com,MX,, Adekunle,Adesiyan,Adekunle.Adesiyan,Adekunle.Adesiyan@domain.com,Adekunle.Adesiyan@domain.com,US,VALENCIA,CALIFORNIA
So far I’m stuck on matching the first and last name columns.
$source = import-csv .ur.csv $change = import-csv .all.csv $results = foreach ($employee in $source) { $update = $change |? {$employee.surname -eq $_.surname -and $employee.givenname -eq $_.givenname} }
submitted by /u/200mg
[link] [comments]
The post Match 2 columns in 2 seperate csv’s then merge one column based on match appeared first on How to Code .NET.