I am trying to find a way to parse a text file and extract the information I want... but not sure as how to do it well. I have a text file that would tell the status of some processes running on the computer, and I want to write a script to analyze it, so it can extract the process name and the status (2nd & 4th column) : (pls see code section)
so far, I have come up with:
For /f "tokens=2,4 delims= " %%a in (D:\file.txt) Do (
If "%%a"=="adminprogram" Echo %%a %%b > result.txt
If "%%a"=="guestprogramr" Echo %%a %%b >>result.txt
If "%%a"=="systemr" Echo %%a %%b >>result.txt
What I wanted to do above is to further extract the 2nd & 4th column information to a text file called "result.txt". Then I will use a third party program to monitor the "result.txt"... when it finds "result.txt" contains the word "stopped" or "stopping", it'll raise an alert.
But the code above doesn't work, as the spaces in 1st column would offset the token I have in the loop... can anyone help with a better way to extract the information? or how to fix up this batch file? Thank you very much.
# Example Text file for analyze
Admin program adminprogram 0005 Running
Guest program guestprogram 2528 Running
System system 8451 Running