BATCH从txt文件中获取特定的字符串

BATCH to get a specific string from a txt file

我想设置一个可以在 txt 文件中找到的参数。 这是一个特定的字符串,它位于字符“=”之后的第一行中。

示例:description.txt

card=0123456789
status=false

我应该取字符串“0123456789”并设置参数 %str%。 我试过这个但它不起作用:

for /f "tokens=2 delims= " %%a in ('type C:\tmp\description.txt^|find "card="') do (
set str=%%a & goto :continue
)
:continue
echo %str%

pause

如何获取第一行“=”后的文字?

TIA

//khs

你应该像这样设置 delims "delims=="

@echo off
for /f "tokens=2 delims==" %%a in ('type "C:\tmp\description.txt" ^|findstr /bi "card="') do (
    set "str=%%a" & goto :continue
)
:continue
echo "%str%"
pause

代码如下:

for /f "tokens=2 delims==" %%a in ('type C:\tmp\description.txt' | find "card"') do echo %%a

肯定需要一个额外的分隔符=。不然不行。