Click here to Skip to main content
15,029,128 members
Please Sign up or sign in to vote.
1.44/5 (3 votes)
See more:
I need to create a .batch code where It reads a text file which have below 3 values in 3 rows.

1234
5678
4321

I need to read the file and assign these 3 values into 3 different variables says ABC, PQR & XYZ, because I have to use these 3 variables for different purpose in same batch file. Please help. Thanks in advance


What I have tried:

I tried with For loop but it did not work as I need to assign these 3 values to 3 different variables as I need to use it in later part of code.

FOR /F %%i IN (file.txt) DO @echo %%i
Posted
Updated 21-May-21 9:45am
v3

You can use your file to define your variables by get line
by line and set accord to the item/var_name in loop by...

For Bat/Cmd file:
@echo off 

set "_var=ABC,PQR,XYZ"
(for %%i in (%_var%)do set/p %%~i=)<.\file.txt



For one line:
@(for %%i in (ABC,PQR,XYZ)do @set /p %%~i=)<.\file.txt


Obs.: Note two things, one that my poor / weak English, the second is that the first 3 lines cannot be blank
   
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900