-3

im looking for for a method to set variables from part of a text. I Have a .txt file where is something like this

part of text
part of text
part of text
part of text
password: 123456
part of text

how can i get a variable 123456 from this file?

I try to use

set var1=<"C:Windows\text.txt"

but it is not working

Any idea mate?

3

1 Answer 1

1

assuming you are working in a cmd shell on windows, this command from the command line may solve your question

for /F  "tokens=2"  %i in ('findstr "password: " "C:Windows\text.txt"') do set var1=%i

while this is if you need the variable in a batch file (where percentage symbols need to be duplicated):

for /F  "tokens=2"  %%i in ('findstr "password: " "C:Windows\text.txt"') do set var1=%%i

for further info I suggest you to read the help message of the for command with

for /?

(especially the first example => FOR /F "eol=; tokens=2,3* delims=, " %i in ...)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.