Page 1 of 1

Extract string from CSV file.

Posted: 17 Mar 2009 11:20
by matheeq
I'm using tasklist command in a batch file to list details of a particular exe.
For e.g

C:\SysinternalsSuite>tasklist /fo CSV /fi "imagename eq radmin.exe"
which returns with
"Image Name","PID","Session Name","Session#","Mem Usage"
"Radmin.exe","3224","Console","0","3,600 K"

I need to extract the Session # which is 0 so I can use it my next step in the batch. Is there a way to extract the Session # value from this CSV for so I can set it to an Env variable and use it later on in my script.

Thanks in advance..

Posted: 17 Mar 2009 12:18
by RElliott63
If the first line is the line that contains your "session#" each time, then you could do something like:

Code: Select all

SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION

For /F "delims=, tokens=4" %%a in (CSVFile) Do (
   Set "Sess=%%d"
   Goto Continue
)

:Continue
Echo Session is !Sess!


(This is just somewhere to start... you might need some tweaking)