Solved Batch script to read the line from a file to variable

October 9, 2013 at 06:41:07
Specs: Windows Server 2003
I am writing a below script to find the particular line like "Final Return Code:"
The value for Final Return Code is 0 or 8

for /f "tokens=* delims= " %i in ('find "Final Return Code:" myfile.txt') do set Return=%i

When i echo the variable %Return% im getting the result as
Final Return Code: 0 or Final Return Code: 8

I want to capture only the value (0 or 8) in the variable not whole line. Any Help would be appreciated


See More: Batch script to read the line from a file to variable

Report •


#1
October 9, 2013 at 08:48:16
✔ Best Answer
for /F "tokens=2 delims=:" %%i in ('find "Final Return Code:" myfile.txt') do set Return=%%i
set Return=%Return: =%


Report •

#2
October 9, 2013 at 08:54:25
::====== script starts here ===============
::
:: suhai.bat 2013-10-09 22:50:10.03
@echo off > NEWFILE & setLocal enableDELAYedeXpansioN

:main
for /f "tokens=4 delims= " %%i in (myfile) do (
set Return=%%i
)
echo.%Return%
goto :eof
::====== script ends here =================

=====================
M2 Golden-Triangle


Report •

Related Solutions


Ask Question