批处理DOS命令findstr查找信息赋值给变量

文件名:test.txt
文件内容:
aaa
str1=c:\aaa
str2=d:\bbb
str3=e\ccc

bbb
str1=aaa
str2=bbb
str3=ccc

要求:
批处理脚本,查找文件中aaa下的str1的值,赋值给变量并在此目录下创建文件,文件内容为bbb中的str1.

第1个回答  推荐于2017-10-08
@echo off&setlocal enabledelayedexpansion
for /f "tokens=1* delims==" %%a in (test.txt) do (
if  "%%b"=="" set "n=%%a"
if "%%a"=="str1" (
if "!n!"=="aaa" set "a=%%b"
if "!n!"=="bbb" set "b=%%b"


cd /d %a%
echo %b% > "%b%.txt"

本回答被提问者采纳
第2个回答  2015-03-06
@echo off
setlocal enabledelayedexpansion
for /f "delims=` tokens=* eol=a" %%a in (test.txt) do (
 if "%%a"=="bbb" goto :n
 set %%a
 set pth=!str1!
)
:n
find /n "bbb" test.txt>temp.tmp
for /f "delims=] tokens=1-2 eol=`" %%a in (temp.tmp) do (
 set l=%%a
 set l=!l:[=!
 set l=!l: =!
 goto :o
)
:o
for /f "delims=` tokens=* eol=` skip=!l!" %%a in (test.txt) do (
 set %%a
)
echo !str1!>!pth!\aaa.txt

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网