Re: Parsing file using FOR command not working asDave expects
From: Matthias Tacke (Matthias.Tacke_at_web.de)
Date: 07/12/04
- Next message: Jerold Schulman: "Re: Parsing file using FOR command not working correctly"
- Previous message: Dave Pink: "Parsing file using FOR command not working correctly"
- In reply to: Dave Pink: "Parsing file using FOR command not working correctly"
- Next in thread: Jerold Schulman: "Re: Parsing file using FOR command not working correctly"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 12 Jul 2004 18:27:44 +0200
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%
>
<snip>
>How can I set the variable "Number" equal to "3166"? Any help would be
>appreciated. Thanks.
>
>Dave
The for command iterates through all lines, a leading delimiter is
ignored, multiple adjacent delimiters are reduced to one.
So the output is as expected (by me).
The regexp in this findstr will output only lines with a number
surrounded by square brackets. In a regexp square brackets mark a range,
the brackets to search for have to be escaped with a backslash, the
asterisk is for multiple occurences of the range 0 to 9 giving a valid
number.
Only lines according to that are passed to the for.
@echo off
FOR /F "tokens=1 delims=[]" %%a in (
'findstr "\[[0-9]*\]" ^<hotfix.txt') DO SET Number=%%a
echo %%a
-- Greetings Matthias________________________________________ For help on nt commands enter in a cmd window: W2K>HH windows.chm::ntcmds.htm XP>HH ntcmds.chm
- Next message: Jerold Schulman: "Re: Parsing file using FOR command not working correctly"
- Previous message: Dave Pink: "Parsing file using FOR command not working correctly"
- In reply to: Dave Pink: "Parsing file using FOR command not working correctly"
- Next in thread: Jerold Schulman: "Re: Parsing file using FOR command not working correctly"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|