I need to get every line in my text in its own variable. Like this:
The text file:
TEMPLATE: Permission, Username, Password;
Admin, Admin, Superflip;
User, Mom, Hi;
I want every line in this file in its OWN variable. Is it possible?
I need to get every line in my text in its own variable. Like this:
The text file:
TEMPLATE: Permission, Username, Password;
Admin, Admin, Superflip;
User, Mom, Hi;
I want every line in this file in its OWN variable. Is it possible?
The following should work...
@echo off & setlocal enabledelayedexpansion
set num=0
::Change "File_Path" to where your file is. If it is in the same directory, just put the name.
for /f "delims=" %%i in (File_Path) do (
set /a num+=1
set line[!num!]=%%i
)
How the script works:
The variable num
is set for use in the for
loop.
The for
loop goes through each line in the file File_Path
setting the line as line
, suffixed by a number.
This script emulates creating an array. To call a specific line, put %line[number_of_line]%
. For instance, to check if line 3
and line 5
are the same, you would put something like
if %line[3]%==%line[5]% echo Line 3 and 5 are the same.
You could also just do this simply:
< filename.txt (
set /p line1=
set /p line2=
set /p line3=
)
That is a much simpler way of doing it.