Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Pulling more text?

0 views
Skip to first unread message

Ben Samuals

unread,
Feb 12, 2004, 2:14:27 PM2/12/04
to
I need to pull a couple of lines from the following text (it is actually in
a file, that is ouput from uptime.exe). I need the line beginning with
"Uptime Report for:" then the line listing Current system uptime. Also, I
can use for with "delims=:, " but how do I get both lines in the output?

\\server1
Current System Uptime: 89 day(s), 1 hour(s), 46 minute(s), 23 second(s)

\\server2
Current System Uptime: 89 day(s), 1 hour(s), 46 minute(s), 23 second(s)

\\server3
Current System Uptime: 89 day(s), 1 hour(s), 46 minute(s), 23 second(s)

\\server4
Current System Uptime: 89 day(s), 1 hour(s), 46 minute(s), 23 second(s).....


This is the output from the uptime.ext (contained in a file) OUTPUT below:

Uptime Report for: \\server1

Current OS: Microsoft Windows 2000, Service Pack 4, Multiprocessor Free.
Time Zone: Eastern Standard Time

System Events as of 2/12/2004 1:28:35 PM:

Date: Time: Event: Comment:
---------- ----------- -------------------
-----------------------------------

Current System Uptime: 89 day(s), 1 hour(s), 46 minute(s), 23 second(s)


------------------------------------------------------------------------
--------

Since 1/1/2004: (Last 42 Days)

System Availability: 100.0000%
Total Uptime: 42d 13h:28m:35s
Total Downtime: 0d 0h:0m:0s
Total Reboots: 0
Total Bluescreens: 0

Notes:
The remote system may be a member of a cluster.
If the remote system is a member of a cluster the reported availability
information applies only to the currently active node, NOT to the
cluster
as a whole.
Uptime Report for: \\server2

Current OS: Microsoft Windows 2000, Service Pack 4, Uniprocessor Free.
Time Zone: Eastern Standard Time

System Events as of 2/12/2004 1:28:43 PM:

Date: Time: Event: Comment:
---------- ----------- -------------------
-----------------------------------
1/24/2004 11:14:11 AM Shutdown
1/24/2004 11:23:12 AM Boot Prior downtime:0d 0h:9m:1s

Current System Uptime: 19 day(s), 2 hour(s), 6 minute(s), 10 second(s)


Phil Robyn [MVP]

unread,
Feb 12, 2004, 2:56:17 PM2/12/04
to
Ben Samuals wrote:

- - - - - - - - - - begin screen capture Win2000 - - - - - - - - - -
c:\cmd>demo\UptimeReport


\\server1
Current System Uptime: 89 day(s), 1 hour(s), 46 minute(s), 23 second(s)

\\server2


Current System Uptime: 19 day(s), 2 hour(s), 6 minute(s), 10 second(s)


c:\cmd>rlist demo\UptimeReport.cmd
=====begin c:\cmd\demo\UptimeReport.cmd ====================
01. @echo off
02. setlocal
03. for /f "tokens=*" %%a in (
04. 'findstr /i "uptime" c:\temp\file.txt
05. ^| findstr /v " Total"'
06. ) do call :format %%a
07. goto :EOF
08. :format
09. set rec=%*
10. set new=
11. if "%rec:~0,6%" equ "Uptime" set rec=%rec:~19%&set new=yes
12. echo/%rec%
13. if not defined new echo/
14. goto :EOF
=====end c:\cmd\demo\UptimeReport.cmd ====================
- - - - - - - - - - end screen capture Win2000 - - - - - - - - - -

--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m a i l

Ben Samuals

unread,
Feb 12, 2004, 3:40:49 PM2/12/04
to
Phil, a few questions on your approach. It works great by the way, it is
just hard for me to understand the formatting. What does the "format:" do?

Then these lines, if you could explain these I would appreciate it...:

set rec=%*
set new=


if "%rec:~0,6%" equ "Uptime" set rec=%rec:~19%&set new=yes

echo/%rec%


if not defined new echo/

Thx, Phil


"Phil Robyn [MVP]" <zipp...@berkeley.edu> wrote in message
news:%230r$yIa8DH...@tk2msftngp13.phx.gbl...

Matthias Tacke

unread,
Feb 12, 2004, 3:50:15 PM2/12/04
to
"Phil Robyn [MVP]" wrote:

You bet me in time Phil, my one findstr was a bit simpler
findstr "\\ (s)"
with otherwise same filter effect.

--
Greetings
Matthias________________________________________
For help on nt commands enter in a cmd window:
W2K>HH windows.chm::ntcmds.htm XP>HH ntcmds.chm

Phil Robyn [MVP]

unread,
Feb 12, 2004, 4:08:38 PM2/12/04
to
Ben Samuals wrote:

> Phil, a few questions on your approach. It works great by the way, it is
> just hard for me to understand the formatting. What does the "format:" do?
>
> Then these lines, if you could explain these I would appreciate it...:
>
> set rec=%*

All arguments ('%*') passed to the subroutine ':format' are assigned to the
environment variable 'rec'.

> set new=

The environment variable 'new' is set to no value.

> if "%rec:~0,6%" equ "Uptime" set rec=%rec:~19%&set new=yes

If the first six characters of environment variable 'rec' are equal to
'Uptime', then set 'rec' to be a substring of itself starting at the 20th
character. So if the value of 'rec' is 'Uptime Report for: \\server1',

....+....1....+....2....+....3
rec = Uptime Report for: \\server1

you can see that the first six characters are equal to 'Uptime', and thus
the new value of 'rec' becomes '\\server1'.

> echo/%rec%

Display the contents of environment variable 'rec' on the screen.

> if not defined new echo/

If the environment variable 'new' has no value, then echo a blank line to the
screen.

Try commenting out the first line in the batch file by inserting two colons,
e.g.,

::@echo off

and then run the batch file and look at the output. This may help you in
gaining a better understanding what it is doing and how it works.

Matthias Tacke

unread,
Feb 12, 2004, 4:15:02 PM2/12/04
to
"Ben Samuals" wrote:

>Phil, a few questions on your approach. It works great by the way, it is
>just hard for me to understand the formatting. What does the "format:" do?
>
>Then these lines, if you could explain these I would appreciate it...:
>
>set rec=%*
>set new=

>if equ "Uptime" set rec=%rec:~19%&set new=yes


>echo/%rec%
>if not defined new echo/
>

Hello Ben,

for /F "tokens=*" takes the whole line from input into %%a
the called sub receives this as multiple arguments, %* puts all passed
args into rec opposed to %1, %2 etc.

A different possible approach is quoting call :format "%%a"
and dequoting with set rec=%~1

see for details on "%rec:~0,6%" in a cmd window:
set /?
for /?

FWIW my version requiring w2k/XP :
:: UptimeRep.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off & setlocal EnableExtensions EnableDelayedExpansion
for /F "tokens=* delims=:" %%A in ('findstr "\\ (s)" uptime.txt') do (
set Line=%%A & set Line=!Line:*: \=\! & echo/!Line! )
:: UptimeRep.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::::

Ben Samuals

unread,
Feb 12, 2004, 4:40:33 PM2/12/04
to
Matthias, can you share it? I need all of the help I can get...

L
"Matthias Tacke" <Matt...@Tacke.de> wrote in message
news:c0gou7$n5o$05$1...@news.t-online.com...

Matthias Tacke

unread,
Feb 12, 2004, 5:52:27 PM2/12/04
to
"Ben Samuals" wrote:

>Matthias, can you share it? I need all of the help I can get...
>

I hope you already found it in the other posting :-)

The change in Phil's would simply be to exchange his 2 piped findstr
with my short one. Findstr allows multiple search strings enclosed by
the quotes. Unique elements of your desired lines are "\\" and "(s)" so
it was easy to combine them.

><snip>


>> >c:\cmd>rlist demo\UptimeReport.cmd
>> >=====begin c:\cmd\demo\UptimeReport.cmd ====================
>> >01. @echo off
>> >02. setlocal
>> >03. for /f "tokens=*" %%a in (
>> >04. 'findstr /i "uptime" c:\temp\file.txt

04. 'findstr "\\ (s)" c:\temp\file.txt'
05. ::removed


>> >05. ^| findstr /v " Total"'
>> >06. ) do call :format %%a
>> >07. goto :EOF
>> >08. :format
>> >09. set rec=%*
>> >10. set new=
>> >11. if "%rec:~0,6%" equ "Uptime" set rec=%rec:~19%&set new=yes
>> >12. echo/%rec%
>> >13. if not defined new echo/
>> >14. goto :EOF
>> >=====end c:\cmd\demo\UptimeReport.cmd ====================
>> >- - - - - - - - - - end screen capture Win2000 - - - - - - - - - -
>> >
>> You bet me in time Phil, my one findstr was a bit simpler
>> findstr "\\ (s)"
>> with otherwise same filter effect.
>>

In my version there was still a delims=: from a previous try which
didn't harm but had no function. So again a corrected version:

:: UptimeRep.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off & setlocal EnableExtensions EnableDelayedExpansion

for /F "tokens=*" %%A in ('findstr "\\ (s)" uptime.txt') do (


set Line=%%A & set Line=!Line:*: \=\! & echo/!Line! )
:: UptimeRep.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::::

The text preceeding the server name is removed by the :


set Line=!Line:*: \=\!

the star representing all leading text up to ": \" and replaced by a
single "\".
Enabledelayedexpansion and the ! are requiring the os's w2k or xp

HTH

0 new messages