Reputation: 87
I would like to set a parameter that I can find in a txt file. This is a specific string, it's found in the first row after the character "=".
Example: description.txt
card=0123456789
status=false
I should take the string "0123456789" and set the parameter %str%. I tried this but it doesn't work:
for /f "tokens=2 delims= " %%a in ('type C:\tmp\description.txt^|find "card="') do (
set str=%%a & goto :continue
)
:continue
echo %str%
pause
how can I get the text after "=" in the first row?
TIA
//khs
Upvotes: 2
Views: 130
Reputation: 15470
Here is the code:
for /f "tokens=2 delims==" %%a in ('type C:\tmp\description.txt' | find "card"') do echo %%a
An extra delimiter =
is definitely needed. Otherwise, it will not work.
Upvotes: 1
Reputation: 18827
You should set the delims like this "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
Upvotes: 3