Batch comparing 2 differents csv files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
toxicz9
Posts: 1
Joined: 20 Oct 2017 03:21

Batch comparing 2 differents csv files

#1 Post by toxicz9 » 20 Oct 2017 03:25

I havent find anything on internet so i need your help.

I have 2 CSV Files that i would like to compare:

the first one is like :

"Name","PrimarySmtpAddress","EmailAddresses"

the second one is like :

"Name","$_.TotalItemSize.Value.ToMB()"

Yy output file must show which name is both in first and second files

And i want to have, as output, a file with all the data in the first files but with the "$_.TotalItemSize.Value.ToMB()" added a the end of each lines.

for exemple it would do something like :

"Name","PrimarySmtpAddress","EmailAddresses","$_.TotalItemSize.Value.ToMB()",

I think i have to use Findstr but i dont know how to use it in my case.

Someone can help me please ?
Thank you.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Batch comparing 2 differents csv files

#2 Post by Squashman » 20 Oct 2017 08:21

Please provide accurate real world examples of both of your input files and then provide an accurate example of what the output should look like. Your pseudo examples can be misleading.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch comparing 2 differents csv files

#3 Post by aGerman » 20 Oct 2017 14:25

Provided at least the name is enclosed in surrounding quotation marks ...

Code: Select all

@echo off &setlocal
set "csv1=file1.csv" &REM "Name","PrimarySmtpAddress","EmailAddresses"
set "csv2=file2.csv" &REM "Name","$_.TotalItemSize.Value.ToMB()"
set "csvout=fileout.csv"

>"%csvout%" (
  for /f usebackq^ tokens^=1*^ delims^=^" %%h in ("%csv1%") do (
    for /f tokens^=1*^ delims^=^" %%j in ('findstr /bc:^^^"\"%%h\"^^^" "%csv2%"') do (
      if "%%j"=="%%h" echo "%%h"%%i%%k
    )
  )
)

Steffen

Post Reply