@echo off
:: Add the fourth number in the third row of all txts in a certain directory
::
set num=0
setlocal enabledelayedexpansion
:: In fact, skip=2 is more efficient to skip the first two lines
for %%i in (*.txt) do (
set file=%%i
for /f "tokens=1* delims=:" %%j in ('findstr /n . !file!') do (
set var=%%k
if %%j equ 3 (set num_=!var:~4,1!)&& set /a num=!num!+!num_!
)
)
The result after the echo is %num%
pause
goto :eof
@echo off
:: Add the numbers in the tenth row and third column of all txt files in a certain directory
:: code by jm 2006-9-9 CMD@XP
setlocal enabledelayedexpansion
for %%i in (*.txt) do (
set file=%%i
set count=0
for /f "skip=9 tokens=3" %%j in (!file!) do (
set /a count+=1
if !count! equ 1 set /a sum+=%%j
)
)
The result after the echo is %sum%
pause