If there are any lines such as comments, they can be dealt with, but following your example:
Code: Select all
@echo off&setlocal enabledelayedexpansion
:: Use only one of the following:
:: To grab the first value of the last line in variable_list.csv...
for /f "usebackq delims=," %%a in ("variable_list.csv") do set "counter=%%a"
:: Or to count the number of lines...
for /f "usebackq delims=" %%a in ("variable_list.csv") do set /a counter+=1
:: Use only one of the following:
:: Write data using a loop...
for %%x in ("variable_name1,#," "variable_name2,#," "variable_name3,#,") do (
for /f "delims=, tokens=1*" %%y in (%%x) do (
set /a counter+=1
echo(!"!!counter!, %%y, %%z,!"!>>"variable_list.csv"
))
:: Or simply...
set /a counter+=1
echo(!"!%counter%, variable_name1, #,!"!>>"variable_list.csv"
set /a counter+=1
echo(!"!%counter%, variable_name2, #,!"!>>"variable_list.csv"
set /a counter+=1
echo(!"!%counter%, variable_name3, #,!"!>>"variable_list.csv"
If you don't want to use delayed expansion, you can remove the
setlocal... and use this in the loop instead:
Code: Select all
set /a counter+=1
call set "output=%%counter%%, %%y, %%z"
call call echo(%%%%"%%%%%%output%%%%%%"%%%%>>"variable_list.csv"
For the individual lines it would be...
Code: Select all
set /a counter+=1
call echo(%%"%%%counter%, variable_name1, #,%%"%%>>"variable_list.csv"
(I'm not too familiar with this !"! quotation technique without delayed expansion.)