Set /p line= for /f "tokens=1-3 delims= " %%1 in ("%line%") do ( set /a j=%%1 set /a k=%%2 set /a l=%%3 ) echo %j% for /f "tokens=4-6 delims= " %%1 in ("%line%") do ( set /a a=%%1 - %j% set /a b=%%2 - %k% set /a c=%%3 - %l% ) for /f "tokens=7-9 delims= " %%1 in ("%line%") do ( set /a d=%%1 - %j% set /a e=%%2 - %k% set /a f=%%3 - %l% ) for /f "tokens=10-12 delims= " %%1 in ("%line%") do ( set /a g=%%1 - %j% set /a h=%%2 - %k% set /a i=%%3 - %l% ) set /a v=(%a%*%e%*%i%+%b%*%f%*%g%+%c%*%d%*%h%-%a%*%h%*%f%-%b%*%i%*%d%-%c%*%g%*%e%)/6 echo %v%