1
votes

I try to find one line in whole text file. Next I need to set this line as a variable.

When i try do this:

set MY_VARIABLE=findstr /I "MY_TEXT" MY.FILE

echo MY_VARIABLE

the result of echo is "findstr /I "MY_TEXT" MY.FILE" i want to see result of "findstr /I "MY_TEXT" MY.FILE" not a command

when i try do this first enter in cmd

for /F "delims=" %%a in ('findstr /I "MY_TEXT" MY.FILE') do set "batToolDir=%%a"

second enter in cmd

echo "%batToolDir%"

i see "the %%a variable is unsuspected"

when i make a file SCRIPT.bat

@echo off

for /F "delims=" %%a in ('set MY_VARIABLE=findstr /I "MY_TEXT" MY.FILE') do set "batToolDir=%%a"

echo "%batToolDir%"

i se anwser ""

What is wrong ? How to make this ?

1

1 Answers

8
votes

Almost done

For command line

for /F "delims=" %a in ('findstr /I "MY_TEXT" MY.FILE') do set "batToolDir=%a"

For batch file double the percent signs

for /F "delims=" %%a in ('findstr /I "MY_TEXT" MY.FILE') do set "batToolDir=%%a"