所有命令必须在Windows命令提示符下执行
我有一个文件data.txt中有几个string:
gargonxx**stringX**moregargon gargonargongargongargon gargon**stringZ**xxgargonxxxx
对于这个数据文件,我想创build一个“库”文件:
stringX = informationx stringY = informationy stringZ = informationz
然后在“库”文件中显示的“信息”之外创buildCMD中的variables,仅在data.txt文件中与库文件匹配的实例中创buildvariables。
varx = string's informationx
然后在命令窗口中转发这些信息。
echo varx
我怎么去
这里是我的图书馆和数据文件
@ECHO OFF SETLOCAL FOR /f "delims==" %%a IN ('set $ 2^>nul') DO "SET %%a=" FOR /f "delims=" %%a IN (data.txt) DO ( FOR /f "tokens=1*delims== " %%L IN (library.txt) DO ( IF /i "%%a"=="%%L" SET $%%a=%%M&ECHO(%%M ) ) ECHO ==== OR ===== SET $ GOTO :EOF
使用文本编辑器来创建库文件。
此批次匹配匹配的实例。
显示信息取决于你想要做什么。
用'data.txt`
lineX lineZ
和library.txt
lineX = informationx lineY = informationy lineZ = informationz
以上批次显示
informationx informationz ==== OR ===== $lineX=informationx $lineZ=informationz
对于修订的规范
@ECHO OFF SETLOCAL FOR /f "delims==" %%a IN ('set $ 2^>nul') DO "SET %%a=" FOR /f "tokens=1*delims== " %%L IN (library.txt) DO ( FINDSTR /i /L "%%L" data.txt >nul IF NOT ERRORLEVEL 1 SET $%%L=%%M&ECHO(%%M ) ECHO ==== OR ===== SET $ GOTO :EOF
(相同的结果,除了line
被string
替代)