Re: Parsing file using FOR command not working correctly

From: Jerold Schulman (Jerry_at_jsiinc.com)
Date: 07/12/04


Date: Mon, 12 Jul 2004 13:07:57 -0400


@echo off
setlocal
for /f "Tokens=1* Delims=[]" %%a in ('type hotfix.txt^|findstr /i /L
/c:"NtServicePack"') do (
 @echo %%b
)

On 12 Jul 2004 09:08:01 -0700, tron9901@msn.com (Dave Pink) wrote:

>I'm using PsLogList from www.sysinternals.com to dump the contents of
>an Event Log. The output is saved to the file hotfix.txt.
>
>Contents of hotfix.txt:
>
>[3166] NtServicePack
> Type: INFORMATION
> Computer: PRDW2K-WEB109
> Time: 6/27/2004 2:02:37 AM ID: 4377
>Windows 2000 Hotfix KB837001 was installed.
>
>
>Using the FOR command, I'm trying to extract just the Event Log
>number; in this case it's 3166. I can't get it to work right.
>
>
>Here's my batch file:
>
>FOR /F "tokens=1 delims=[]" %%a in (hotfix.txt) DO SET Number=%%a
>@ECHO %Number%
>
>
>Here's the output of my batch file:
>
>C:\>FOR /F "tokens=1 delims=[]" %%a in (hotfix.txt) DO SET Number=%%a
>
>C:\>set Number=3166
>
>C:\>set Number= Type: INFORMATION
>
>C:\>set Number= Computer: PRDW2K-WEB109
>
>C:\>set Number= Time: 6/27/2004 2:02:37 AM ID: 4377
>
>C:\>set Number=Windows 2000 Hotfix KB837001 was installed.
>
>Windows 2000 Hotfix KB837001 was installed.
>
>
>How can I set the variable "Number" equal to "3166"? Any help would be
>appreciated. Thanks.
>
>Dave

Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com



Relevant Pages

  • Re: Service will not start after a reboot
    ... and the whole point of writing it as a service was to ... clues in the Event log and there are no dependencies on other services. ... Use the Task Scheduler to run the following batch file at boot ... echo %date% %time%>>c:\Waldy.log ...
    (microsoft.public.windowsxp.general)
  • Parsing file using FOR command not working correctly
    ... Windows 2000 Hotfix KB837001 was installed. ... I'm trying to extract just the Event Log ... Here's the output of my batch file: ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: Reporting erros in batch files to the Event Log
    ... file does some file copies to a backup server. ... I would like is the batch file to report any errors to the Event Log. ... logevent.exe comes with the Windows Resource Kit. ...
    (microsoft.public.windowsxp.general)
  • Cannot stop Event Log service
    ... On Windows 2000 boxes, I want to temporarily stop the "event log" service. ... My goal is to programmatically empty ... the secevent.evt log with a batch file, but I need to stop the service in ...
    (microsoft.public.windows.server.general)
  • Re: Find out when the computer was rebooted?
    ... > such event be written into the Event Log? ... by using the Task Scheduler to run the following batch file ... at boot time: ... @echo off ...
    (microsoft.public.windows.server.general)