Sunday, 15 June 2014

batch file - .BAT to filter data in a csv with a line containing in the 3rd token -



batch file - .BAT to filter data in a csv with a line containing in the 3rd token -

i have sample csv file

alvin,am,7,11,math,sci

mary,am,7,11,math,sci

andrew,am,11,3,english,history

i want create resulting csv

alvin,am,7,11,math,sci

mary,am,7,11,math,sci

i have code

@echo off /f "eol=- tokens=1,2,3,4,5,6 delims=," %%1 in (abcd.csv) if %%3 equ 7 echo %%1 %%2 %%3 %%4 %%5 %%6 >> output.csv

i readied output.csv considering utilize redirection code >> appends rather > creates. please allow me know why isn't working.

just replace spaces commas:

@echo off del output.csv /f "eol=- tokens=1,2,3,4,5,6 delims=," %%1 in (abcd.csv) if %%3 equ 7 echo %%1,%%2,%%3,%%4,%%5,%%6 >> output.csv

and you'll have expected result:

alvin,am,7,11,math,sci mary,am,7,11,math,sci

also improve delete output.csv before appending (to avoid duplication of info in case of multiple phone call of script).

batch-file csv

No comments:

Post a Comment