Extract string from CSV file.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
matheeq
Posts: 1
Joined: 17 Mar 2009 11:08

Extract string from CSV file.

#1 Post by matheeq » 17 Mar 2009 11:20

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..

RElliott63
Expert
Posts: 80
Joined: 04 Feb 2009 10:03

#2 Post by RElliott63 » 17 Mar 2009 12:18

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)

Post Reply