I am new to windows batch scripting and am having trouble extracting information from a text file. My script needs to iterate over a text file with an unknown number of lines and search for the string “Installer ID:”. Once this is found I need to store whatever information is on the right hand side of the colon.
For example if my text file looked as follows:
SomeText.txt
------------------------
Installer Date: 2010_10_24_24345
OXF BUILD ID: OXF-12223
Installer ID: OTFI-316
Excel ID: 2-10186
BUILD DBID: 296414
Version: 6.2
I would want to store:
OTFI-316
I have come so far with something like this:
@echo off
setlocal EnableDelayedExpansion
set file=build_info.txt
FOR /F "tokens=*" %%i IN (%file%) DO (
findstr Installer ID: %%i
if %errorlevel%==0 (
set installer_id=SUBSTRING I
)
but I am having problems searching %%i for “Installer ID:” with its two words and colon, and from there I am unsure how to properly substring %%i.
Put the FINDSTR command within the FOR IN() clause, and parse the results.
I set DELIMS to colon and space so that all of the following lines would give the correct result:
You want everything after the 2nd token (the
*intokens=2*).