title: Windows batch script to parse CSV file and output a text file
body: <p>I've seen a response on another page (<a href="https://stackoverflow.com/questions/6470570/help-in-writing-a-batch-script-to-parse-csv-file-and-output-a-text-file">Help in writing a batch script to parse CSV file and output a text file</a>) - brilliant code BTW:</p>
  
  <pre><code>@ECHO OFF
  IF "%~1"=="" GOTO :EOF
  SET "filename=%~1"
  SET fcount=0
  SET linenum=0
  FOR /F "usebackq tokens=1-10 delims=," %%a IN ("%filename%") DO ^
  CALL :process "%%a" "%%b" "%%c" "%%d" "%%e" "%%f" "%%g" "%%h" "%%i" "%%j"
  GOTO :EOF
  
  :trim
  SET "tmp=%~1"
  :trimlead
  IF NOT "%tmp:~0,1%"==" " GOTO :EOF
  SET "tmp=%tmp:~1%"
  GOTO trimlead
  
  :process
  SET /A linenum+=1
  IF "%linenum%"=="1" GOTO picknames
  
  SET ind=0
  :display
  IF "%fcount%"=="%ind%" (ECHO.&amp;GOTO :EOF)
  SET /A ind+=1
  CALL :trim %1
  SETLOCAL ENABLEDELAYEDEXPANSION
  ECHO !f%ind%!!tmp!
  ENDLOCAL
  SHIFT
  GOTO display
  
  :picknames
  IF %1=="" GOTO :EOF
  CALL :trim %1
  SET /a fcount+=1
  SET "f%fcount%=%tmp%"
  SHIFT
  GOTO picknames
  </code></pre>
  
  <p>It works brilliantly for an example csv file I made in the format:</p>
  
  <pre><code>Header,Name,Place
  one,two,three
  four,five,six
  </code></pre>
  
  <p>However the actual file I want to change comprises of 64 fields - so I altered the <code>tokens=1-10</code> to <code>tokens=1-64</code> and increased the <code>%%a</code> etc right up to 64 variables (the last being called <code>%%BL</code> for example). Now, however, when I run the batch on my 'big' csv file (with the 64 tokens) nothing happens. No errors (good) but no output! (bad). If anyone can help that would be fantastic... am soooo close to getting the whole app working if I can just nail this last bit! Or if anyone has some example code that will do similar for an indefinite number of tokens... Ultimately I want to make a string which will be something like:</p>
  
  <pre><code>field7,field12,field15,field18
  </code></pre>