Read from CSV file using batch script

January 27, 2015 at 22:58:40
Specs: Windows 7
I have csv files with 4 rows:

if i used below command:
@echo off
setlocal enabledelayedexpansion

set /p header=<test.csv

for /f "skip=1 tokens=*" %%A in (test.csv) do (
set inline=%%A

for /f "tokens=1-4 delims=," %%1 in ("!inline!") do (
set col1=%%1&set col2=%%2&set col3=%%3&set col4=%%$
echo %%1,%%2,%%3,%%4>output2.csv


type output2.csv

The result will be:

what if i have 100 lines and i want to display maybe few lines?

i want to display 4 columns but i want to display like this:

First person = john,16,male,9898989898
Second person = tom,19,male,8787878787
Third person = tia,22,female,6767676767

any help?

message edited by Zaili

See More: Read from CSV file using batch script

Report •

June 15, 2015 at 00:16:08

Report •

June 15, 2015 at 21:15:48
change this line:
echo %%1,%%2,%%3,%%4>output2.csv

echo %%1,%%2,%%3,%%4>>output2.csv

be sure to "clear" output2.csv prior to each run unless you want incremental additions.

Report •
Related Solutions

Ask Question