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
script to compare 2 csv files and concatenate
Moderator: DosItHelp
Re: script to compare 2 csv files and concatenate
This works here with the sample data:
It uses a helper batch file called repl.bat from - viewtopic.php?f=3&t=3855
It uses a helper batch file called repl.bat from - viewtopic.php?f=3&t=3855
Code: Select all
@echo off
set "file1=file1.txt"
set "file2=file2.txt"
for /f "tokens=1,* delims=," %%a in ('type "%file1%" ') do (
type "%file2%"|repl "^%%a" "%%b" m >"%file2%.tmp"
move "%file2%.tmp" "%file2%" >nul
)
echo done
pause
-
- Posts: 2
- Joined: 23 Jul 2013 04:21
Re: script to compare 2 csv files and concatenate
Hello foxidrive,
It worked well..
Thank you so much for your response.
It worked well..
Thank you so much for your response.