This filters the line containing the word "Attempting" and splits it up into tokens separated by the delimiters )
=
and a space
You can count the tokens from the left end of the line and the 9th, 11th and 14th section of the line, which are separated by ")= " are the items which you want in the variables. Each token is applied to %%a
%%b
%%c
in order.
Remove the echo
sections and they will set the variables.
@echo off
for /f "tokens=9,11,14 delims=)= " %%a in ('type "file.txt" ^| find "Attempting"') do (
echo set "HOST=%%a"
echo set "PORT=%%b"
echo set "SERVICE_NAME=%%c"
)
pause
To describe the tokens:
If you have a string like this =abc = def=ghi
and you apply delimiters of a space
and equals =
then the sections that are left are "abc" "def" "ghi" (without the quotes) and they call the sections 'tokens'. If you use tokens=2
then %%a in this case will be set to def
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST =10.184.10.90)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME = ORCL)))
This line above from the original example when using delims of )= and space, will have the tokens below, and if you count them then the IP address is the 9th token. Note that the delimiters of )= and space have vanished, as that is the purpose of the delimiters.
Attempting
to
contact
(DESCRIPTION
(ADDRESS
(PROTOCOL
TCP
(HOST
10.184.10.90
(PORT
1521
(CONNECT_DATA
(SERVICE_NAME
ORCL
I hope that is clear.