batch file to read a 2nd field in flatfile (dos)

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sabercats
Posts: 6
Joined: 18 May 2011 15:54

batch file to read a 2nd field in flatfile (dos)

#1 Post by sabercats » 19 Jun 2012 17:29

I have a log file \from\where\some\directory\log.txt

Code: Select all

54,SABERCATSWIN7x64,sabercats-pc,,,2012-06-19 15:36:42.000,,,,,,,
3,SABERCATSWIN7,sabercats-pc,,,2012-06-18 15:44:53.000,,,,,,,,


How do we write dos batch file to get the hostname of the old start time (automatically in 2nd lines) like
sabercatswin7
and then run execute script C:\script\removeit.exe -release=SABERCATSWIN7

I want the batch file to run in scheduler to remove the old hostname.
Thanks,

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: batch file to read a 2nd field in flatfile (dos)

#2 Post by aGerman » 19 Jun 2012 17:44

Probably that way:

Code: Select all

for /f "usebackq skip=1 tokens=2 delims=," %%i in ("C:\from\where\some\directory\log.txt") do (
  C:\script\removeit.exe -release=%%i
)

Regards
aGerman

sabercats
Posts: 6
Joined: 18 May 2011 15:54

Re: batch file to read a 2nd field in flatfile (dos)

#3 Post by sabercats » 20 Jun 2012 11:04

Thanks, it works.

Post Reply