Grab info from the next line

  • Thread starter Thread starter Mr. Novice
  • Start date Start date
M

Mr. Novice

Hello, I'm wanting to search for a drive letter in the
output listed below and when it finds a matching drive
letter, set a variable to equal the second token from the
line below it. For example, if I search for C:\ a variable
would be set to equal 90 or if I search for D:\ a variable
would be set to equal 95. Does anybody know how to do this?

Thanks!

Chad

ntStatusFSDriveLetter "C:\"
ntStatusFSPcntCritical 90
ntStatusFSDriveLetter "D:\"
ntStatusFSPcntCritical 95
ntStatusFSDriveLetter "W:\"
ntStatusFSPcntCritical 95
 
Mr. Novice said:
Hello, I'm wanting to search for a drive letter in the
output listed below and when it finds a matching drive
letter, set a variable to equal the second token from the
line below it. For example, if I search for C:\ a variable
would be set to equal 90 or if I search for D:\ a variable
would be set to equal 95. Does anybody know how to do this?

Thanks!

Chad

ntStatusFSDriveLetter "C:\"
ntStatusFSPcntCritical 90
ntStatusFSDriveLetter "D:\"
ntStatusFSPcntCritical 95
ntStatusFSDriveLetter "W:\"
ntStatusFSPcntCritical 95

Here's one way:

- - - - - - - - - - begin screen capture - - - - - - - - -
<Win2000> c:\cmd>type %temp%\YourOutput.file
ntStatusFSDriveLetter "C:\"
ntStatusFSPcntCritical 90
ntStatusFSDriveLetter "D:\"
ntStatusFSPcntCritical 95
ntStatusFSDriveLetter "W:\"
ntStatusFSPcntCritical 95

<Win2000> c:\cmd>demo\ReadFromNextLine "C:"
result=90

<Win2000> c:\cmd>demo\ReadFromNextLine "D:"
result=95

<Win2000> c:\cmd>demo\ReadFromNextLine "W:"
result=95

<Win2000> c:\cmd>rlist c:\cmd\demo\ReadFromNextLine.cmd
=====begin c:\cmd\demo\ReadFromNextLine.cmd ====================
01. @echo off
02. setlocal
03. for /f "tokens=1* delims=:" %%a in (
04. 'findstr /n /c:"%~1" c:\temp\YourOutput.file'
05. ) do set /a line_number = %%a + 1
06. for /f "tokens=2" %%b in (
07. 'findstr /n /v /c:"Osama Bin Laden" c:\temp\YourOutput.file
08. ^| findstr /b "%line_number%:"'
09. ) do set result=%%b
10. set result
=====end c:\cmd\demo\ReadFromNextLine.cmd ====================
- - - - - - - - - - end screen capture - - - - - - - - -
 
That's great! Thanks!

Chad


-----Original Message-----


Here's one way:

- - - - - - - - - - begin screen capture - - - - - - - - -
<Win2000> c:\cmd>type %temp%\YourOutput.file
ntStatusFSDriveLetter "C:\"
ntStatusFSPcntCritical 90
ntStatusFSDriveLetter "D:\"
ntStatusFSPcntCritical 95
ntStatusFSDriveLetter "W:\"
ntStatusFSPcntCritical 95

<Win2000> c:\cmd>demo\ReadFromNextLine "C:"
result=90

<Win2000> c:\cmd>demo\ReadFromNextLine "D:"
result=95

<Win2000> c:\cmd>demo\ReadFromNextLine "W:"
result=95

<Win2000> c:\cmd>rlist c:\cmd\demo\ReadFromNextLine.cmd
=====begin c:\cmd\demo\ReadFromNextLine.cmd ====================
01. @echo off
02. setlocal
03. for /f "tokens=1* delims=:" %%a in (
04. 'findstr /n /c:"%~1" c:\temp\YourOutput.file'
05. ) do set /a line_number = %%a + 1
06. for /f "tokens=2" %%b in (
07. 'findstr /n /v /c:"Osama Bin Laden" c:\temp\YourOutput.file
08. ^| findstr /b "%line_number%:"'
09. ) do set result=%%b
10. set result
=====end c:\cmd\demo\ReadFromNextLine.cmd ====================
- - - - - - - - - - end screen capture - - - - - - - - -

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