Hi to everybody,
I need your help to solve a problem for which I could not find a solution.
By specifically:
I have a text file (list.txt) consists of n rows and associated name
It's generated by a batch file using the command findstr / N.
list.txt is like this:
1:PIPPO
2:PLUTO
3:PALLA
..
..
n:ZUZZO
but I need its start from zero 0 like this:
0:PIPPO
1:PLUTO
2:PALLA
..
..
n-1:ZUZZO
I wrote this batch, but doesn't work!
for /f "tokens=1,2* delims=:" %%a in (list.txt) do (
set wa=%%a
set /a tot=%wa%-1
echo %tot%:%%b>>new_list.txt
)
where is the mistake?
how can I fix it?
as optional solution is there a possibility to use findstr /n and start the line number from zero?
PLEASE HELP ME!!!
I stopped on this point from some months.
I don't see the light at the end of this tunnel.
arithmetic operations in batch file, using variables -SOLVED
Moderator: DosItHelp
arithmetic operations in batch file, using variables -SOLVED
Last edited by microfot on 10 Feb 2012 15:50, edited 1 time in total.
Re: arithmetic operations in batch file, using variables
You need to use Delayed Expansion with the code you are using.
Re: arithmetic operations in batch file, using variables
it doesn't work equally 

Re: arithmetic operations in batch file, using variables
'
try delayed Expansion
try delayed Expansion
Code: Select all
@echo off &setlocal enableDelayedExpansion
for /f "tokens=1,2* delims=:" %%a in (list.txt) do (
set "wa=%%a"
set /a tot=wa-1
echo.!tot!:%%b>>new_list.txt
)
type new_list.txt
pause
Code: Select all
@echo off
setlocal /?
pause
Re: arithmetic operations in batch file, using variables
microfot wrote:it doesn't work equally
It does work when used correctly.
Re: arithmetic operations in batch file, using variables
dear Ed Dyreen
you are the nation saviour!
Thanks a lot
very long time trouble solved in few minutes!
Thanks also to Squashman
I had not understood the correct way to use your your help
you are the nation saviour!
Thanks a lot

very long time trouble solved in few minutes!
Thanks also to Squashman
I had not understood the correct way to use your your help

Re: arithmetic operations in batch file, using variables
microfot wrote:Thanks also to Squashman
I had not understood the correct way to use your your help
I thought maybe you knew how to do it.
Ed showed you exactly what I was referring to.