问题描述
我尝试在整个文本文件中找到一行.接下来,我需要将此行设置为变量.
I try to find one line in whole text file. Next I need to set this line as a variable.
当我尝试这样做时:
回声MY_VARIABLE
echo MY_VARIABLE
echo的结果是"findstr/I" MY_TEXT"MY.FILE"我想查看"findstr/I" MY_TEXT"MY.FILE"的结果而不是命令
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
当我尝试这样做时首先输入cmd
when i try do thisfirst enter in cmd
第二次输入cmd
我看到" %% a变量是不可疑的"
当我创建文件SCRIPT.bat
when i make a file SCRIPT.bat
对于/F"delims =" %% a in('set MY_VARIABLE = findstr/I"MY_TEXT" MY.FILE'),确实设置了"batToolDir = %% a"
for /F "delims=" %%a in ('set MY_VARIABLE=findstr /I "MY_TEXT" MY.FILE') do set "batToolDir=%%a"
回显%batToolDir%"
echo "%batToolDir%"
我自己回答"
怎么了?如何做到这一点?
What is wrong ? How to make this ?
推荐答案
即将完成
对于命令行
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"
这篇关于在文件中查找文本并将其设置为变量.批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!