I'm attempting to write a script which will read a text file, find 6 different strings/rows, and store those six strings into six different variables within the batch script. So far, my batch script will set the last known string into all six variables. May I have some trouble shooting assistance?
Thanks in advance!
Source file: testFile.txt
Code: Select all
Speed : 111111111 Bytes/sec.
Speed : 222222222 Bytes/sec.
Speed : 333333333 Bytes/sec.
Speed : 444444444 Bytes/sec.
Speed : 555555555 Bytes/sec.
Speed : 666666666 Bytes/sec.
Batch Script thus far
Code: Select all
@echo on
setlocal ENABLEDELAYEDEXPANSION
::Declare temp space for 6 pass numbers (3 trials, write, read)
set str_pass_1_write=0
set str_pass_1_read=0
set str_pass_2_write=0
set str_pass_2_read=0
set str_pass_3_write=0
set str_pass_3_read=0
:setNumbers
for /f "tokens=*" %%a in ('findstr "Bytes/sec." testFile.txt') do (
if %str_pass_1_write%==0 set str_pass_1_write=%%a
if %str_pass_1_read%==0 set str_pass_1_read=%%a
if %str_pass_2_write%==0 set str_pass_2_write=%%a
if %str_pass_2_read%==0 set str_pass_2_read=%%a
if %str_pass_3_write%==0 set str_pass_3_write=%%a
if %str_pass_3_read%==0 set str_pass_3_write=%%a
)
goto:setNumbers_End
:setNumbers_End
echo %str_pass_1_write%
echo %str_pass_1_read%
echo %str_pass_2_write%
echo %str_pass_2_read%
echo %str_pass_3_write%
echo %str_pass_3_read%
goto:EOF
:EOF