I have written a script to pull specific event data from .csv logs.
2021_06_04 09:00.00, online, Serial#001, 50.10.10.10 2021_06_04 09:01.00, online, Serial#002, 50.10.10.11 2021_06_04 09:01.00, read, Serial#002, apples, clear 2021_06_04 09:01.00, online, Serial#003, 50.10.10.12 2021_06_04 09:01.00, offline, Serial#001 2021_06_04 09:02.00, read, Serial#002, bananas, clear 2021_06_04 09:03.00, read, Serial#003, apples, reject 2021_06_04 09:04.00, read, Serial#002, apples, clear 2021_06_04 09:05.00, read, Serial#003, apples, clear
First I find all machines that came online and store their IP addresses to variables named after their Serial Numbers
for /f "delims=, tokens=3,4" %%a in (
'type "Log.csv"^|findstr "online"'
) do (
set %%a=%%b
Now this has assigned variables as expected and as follows
%Serial001% = 50.10.10.10 %Serial002% = 50.10.10.11 %Serial003% = 50.10.10.12
Now I want to find each "read" event per machine. Number of events are counted to create a "variable set"
set /p Search=Search:
set EventCount = 0
for /f "delims=, tokens=1,3,5" %%a in (
'type "Log.csv"^|findstr "read"^|findstr %search%'
) do (
set /a EventCount+=1
call set EventTime[%%EventCount%%]=%%a
call set Machine[%%EventCount%%]=%%b
call set Decision[%%BagCount%%]=%%c
)
set TotalCount=%EventCount%
Now I can display each data set, using 'choice' to scroll through the event count
THE MILLION DOLLAR QUESTION!
On the second line I want to add the Machine IP address which was stored in a variable, named after the machine...
%%Machine%% is outputting %Serial#002%
echo. Search: %search%
echo. Machine: !Machine[%EventCount%]! on %%Machine%%
echo Decision: !Decision[%BagCount%]! @ !EventTime[%EventCount%]!
echo.
echo. %EventCount% of %TotalCount%
expected output
Search: Apples Machine: Serial#002 on 50.10.10.10 Decision: Clear @ 2021_06_04 09:01.00 1 of 4
How do I display the IP address by expanding the variable that is named after a variable...
I've tried all combinations of delayed expansion without luck. I want to recall this IP address for other functions also, not just display purposes.
Any direction would be very much appreciated!!