Kiwi Rupela
Kiwi Rupela

Reputation: 2348

read specific value from a txt file using batch file

I am new to writing a batch file I want to read some specific value from a txt file using batch file

here is my txt file

PARAM1=value1
PARAM2=value2
PARAM3=value3
PARAM4=value4
PARAM5=value5
PARAM6=value6

here is my batch file

 setlocal enabledelayedexpansion
 set /a _index=1

 for /f "delims=" %%a in (param.txt) do (
  set "key!_index!=%%a"
  set /a _index+=1
 )

 echo searching for !key1!, !key2!, !key3!, !key4!, !key5!
 echo %_index%
 pause

but in !key1!,!key2! i am getting values like PARAM1=value1 i want to read it as !key1! = value1 can anyone help me from this.

Upvotes: 0

Views: 54

Answers (1)

JosefZ
JosefZ

Reputation: 30103

Maybe the following changes could help:

setlocal enabledelayedexpansion
set /a _index=1

for /f "tokens=1* delims==" %%a in (param.txt) do (
    set "_key!_index!=%%b"
    set /a _index+=1
)
set _
pause

Upvotes: 2

Related Questions