user2666981
user2666981

Reputation: 11

Batch File Store Line Variables And Sum Them Up

My input file Count.txt contains the following:

] /Count 1
] /Count 2

I am trying to add the numeric characters at the end of each line and store it to another file or store it to another variable. I am not able to do it with the following batch file script:

setlocal enabledelayedexpansion
set count=0
for /f "tokens=3 delims= " %%i in ('findstr Count Count.txt') do (
set /a count=%%i + %count%
echo !count! > finalcount.txt
) 
endlocal

The output I am getting is 2.

Please help.

Upvotes: 1

Views: 1039

Answers (1)

Endoro
Endoro

Reputation: 37569

try this:

@echo off &setlocal enabledelayedexpansion
set count=0

(for /f "tokens=3" %%i in ('findstr "Count" Count.txt') do (
set /a count+=%%i
echo !count! 
))> finalcount.txt

Upvotes: 2

Related Questions