Parse CSV with Batch Script

Here’s a basic method of parsing a CSV file using Microsoft Batch.

The following code will allow me to use all the CSV fields. Let’s suppose the CSV contains the following:

Example CSV

Name, Email, Username, Password
John Doe,,jdoe123,secretpassword
Jane Doe,,janeybug1,topsecret

Batch Script

@echo off
for /F usebackq tokens=* delims=, %%a in (c:tempusers.csv) do (
echo Name:  %%a
echo Email:  %%b
echo Username:  %%c
echo Password:  %%d

Output from Batch

Name:  John Doe
Username:  jdoe123
Password:  secretpassword
Name:  Jane Doe
Username:  janeybug1
Password:  topsecret

[stextbox id=info caption=Note]If the CSV file you are working with uses quotes also, then when using the variable, specify %%~a to strip the quotes from the variable. See help for[/stextbox]

If you are only interested in a few columns, you could use the following for the tokens= specifier in the for loop.


That will only return the 3rd and 4th result based on the , delimiter and in this case it is the username and password. You still use %%a then %%b for your variables.