Solved reading new line separator in batch script

July 2, 2012 at 02:57:01
Specs: Windows 7
reading new line code in batch script
hi , i have a file with many items , excel file saved as text file , i'm trying to read contents and assign each one to a variable so that i can deal with them separately , but when i start it runs to the end without stopping at the end of each line , here what i did:
set n=0
for /f "tokens=1-8 delims=NL " %%a in (C:\Fuel_Prices.txt) do (

set /a n=%n%+1
set Scenario_%n%=%%a
set Day_%n%=%%b
set Fueltype_%n%=%%d
set Fuelname_%n%=%%e
set Stat_%n%=%%f
set Price_%n%=%%g
set cost_%n%=%%h)
echo %n%

for i=1,n do
echo %Fueltype_i%

where did i do wrong ??? any help , because its not counting . n remains 0 , and it read the whole file while i need one line only

See More: reading new line separator in batch script

Report •

July 2, 2012 at 11:25:51
✔ Best Answer
is the excel-saved file comma-separated values? I'll make that assumption for now.
try this out:

@echo off & setlocal enabledelayedexpansion
set n=0
for /f "tokens=1-8 delims=," %%a in (C:\Fuel_Prices.txt) do (
set /a n+=1
set Scenario_!n!=%%a
set Day_!n!=%%b
set Fueltype_!n!=%%d
set Fuelname_!n!=%%e
set Stat_!n!=%%f
set Price_!n!=%%g
set cost_!n!=%%h)
echo !n!
echo done loading. hit any key for results:
for /L %%i in (1,1,%n%) do (
echo !Fueltype_%%i!

Report •

July 2, 2012 at 23:16:18
thanks very much , its working

Report •
Related Solutions

Ask Question