Export certain columns from a csv to a new csv using batch

January 27, 2016 at 08:40:02
Specs: Windows 2008
I have the following CSV file with 30+ columns in a csv called thirtycol.csv.
597156,1,"XDTEST","925598024","INVOIC","<none>","",5,1,1453910813,0,0,"E","D 96AEAN008","<none>","D 96AEAN008","380","#2016\01\27\16\DOC597156.RPT","","","0000000082308737","NAP9","100731 NAPPRD NAPPRDHOLD","",0,"#2016\01\27\16\DOC597156",8634,398,,,,,"","","",,,,,"",,,,,,"","",,,,,,,,,,,,,,,"",""

When I run the below script I get the correct first two column 3 &4 but not 17 and 21!
@echo off>fourcol.csv

:: Return four columns from a .csv file

for /f "tokens=1-4* delims=," %%1 in (thirtycol.csv) do (
echo %%3,%%4,%%17,%%21>>fourcol.csv
type fourcol.csv
I tried this with a csv when the column are numbered 1-60 and the script returns the correct column number example 3,4,17,21 but when it is a the original data as above It returns XDTEST,925598024,5971567,11 . This does make sense as 5971567 and 11 on the file.

Any help would be greatly appreciated.

See More: Export certain columns from a csv to a new csv using batch

Report •

January 27, 2016 at 08:49:46
Assuming US ASCII, the 17th column would be %%A, and the 21st would be %%E.

How To Ask Questions The Smart Way

Report •
Related Solutions

Ask Question