script to compare 2 csv files and concatenate
Posted: 23 Jul 2013 04:30
I was trying the below script to compare strings in 2 files and concatenate the matching ones. How ever it doesnt work as expected:
for /f "tokens=1-4 delims=," %%i in (File2.csv) do @findstr "%%i" File1.csv & (for /f "tokens=1,2* delims=," %%m in ('findstr /i /L "%%i" File1.csv') do @echo %%n %%j %%k>>output.csv)
File1
------
189208,Tom
918648,Viktor
643297,Sam
File2
------
189208,London,20130718
918648,Essex,20130807
189208,Berkshire,20130716
918648,Middlesex,20130809
643297,Yorkshire,20130718
Expected Output
----------------------
Tom,London,20130718
Viktor,Essex,20130807
Tom,Berkshire,20130716
Viktor,Middlesex,20130809
Sam,Yorkshire,20130718
for /f "tokens=1-4 delims=," %%i in (File2.csv) do @findstr "%%i" File1.csv & (for /f "tokens=1,2* delims=," %%m in ('findstr /i /L "%%i" File1.csv') do @echo %%n %%j %%k>>output.csv)
File1
------
189208,Tom
918648,Viktor
643297,Sam
File2
------
189208,London,20130718
918648,Essex,20130807
189208,Berkshire,20130716
918648,Middlesex,20130809
643297,Yorkshire,20130718
Expected Output
----------------------
Tom,London,20130718
Viktor,Essex,20130807
Tom,Berkshire,20130716
Viktor,Middlesex,20130809
Sam,Yorkshire,20130718