Kris_1996
Kris_1996

Reputation: 11

Batch file Variables don't work

 @ECHO OFF
    @cls
    @set wpisane1=
    @for /f "tokens=1" %%a in ('type C:\zadanie\1.txt ') do @echo %%a
    @echo ma
    @set wpisane2= 
    @for /f "tokens=3" %%b in ('type C:\zadanie\1.txt ') do @echo %%b 
    @echo lat

@echo. 
@set wpisane3=
@for /f "tokens=5" %%c in ('type C:\zadanie\1.txt ') do @echo %%c
@echo ma
@set wpisane4= 
@for /f "tokens=7" %%d in ('type C:\zadanie\1.txt ') do @echo %%d 
@echo lat 
@echo.
@set a1=29
@set a2=35
@set /a suma=%a1%+%a2%
@echo Razem maja %suma% lat(a)
@pause
@exit

My question is: How to set %%b and %%d as a1 and a2? How can I do this? Is it possible ? Please answer my question as fast as it possible. The text file contains that:

radek ma 29 lat jarek ma 35 lat 

Upvotes: 0

Views: 64

Answers (1)

JosefZ
JosefZ

Reputation: 30103

As soon as possible? Pay a little of your time to learning, start with results of next code snippet.

@ECHO OFF >NUL
@SETLOCAL enableextensions enabledelayedexpansion
for /f "tokens=1-8*" %%g in ('type C:\zadanie\1.txt') do (
  rem set /a "a1=%%i"
  rem set /a "a2=%%m"
  rem set /a "suma=!a1!+!a2!"
  set /a "suma=%%i+%%m"
  @echo g=%%g h=%%h i=%%i j=%%j k=%%k l=%%l m=%%m n=%%n o=%%o suma=!suma!
)
@ENDLOCAL
goto :eof

Upvotes: 1

Related Questions