Find text in file and set it as a variable. Batch file

核能气质少年 提交于 2019-12-19 10:44:07

问题


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:


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"


来源:https://stackoverflow.com/questions/22198458/find-text-in-file-and-set-it-as-a-variable-batch-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!