I am trying to load a column from a CSV file into a variable. My CSV file contains empty columns so can have ,, which seems to be ignored by the following:
for treats consecutive delimiters as one. In most cases, this is helpful. Sometimes it is not.
So you have to write your lines in a way, that for can handle as you intended.
Read every line of your file as a whole, add a quote at the beginning and at the end and replace every , with ",", resulting in
"chris","","steve","deon","bryan","mark","anthony"
This can happily be parsed with another for. The tilde in %%~b removes the surrounding quotes.
@echo off
setlocal enabledelayedexpansion
FOR /F "tokens=*" %%a in (csvfile.csv) do (
set line="%%a"
for /f "tokens=3 delims=," %%b in ("!line:,="^,"!") do echo %%~b
)