MrEyes
asked on
Parsing command output
Anybody got any ideas on how to acheive the following:
I need to run a command within a windows batch script, get the result of the call, parse out a specific value, check it is numeric and then add 1 to it.
The command and output in question is:
C:\Inetpub\AdminScripts>ad sutil ENUM /P W3SVC
[/W3SVC/Info]
[/W3SVC/Filters]
[/W3SVC/1]
[/W3SVC/2]
[/W3SVC/3]
C:\Inetpub\AdminScripts>
I need to get the last line ([/W3SVC/3]) extract the 3 and add 1 to it. In other words the result of the batch execution would output 4
I need something that will be smart enough to handle situations where the output is something like this aswell
C:\Inetpub\AdminScripts>ad sutil ENUM /P W3SVC
[/W3SVC/Info]
[/W3SVC/Filters]
[/W3SVC/1]
I am fairly certain this can be done with FOR but I am not certain on how to implement it
I need to run a command within a windows batch script, get the result of the call, parse out a specific value, check it is numeric and then add 1 to it.
The command and output in question is:
C:\Inetpub\AdminScripts>ad
[/W3SVC/Info]
[/W3SVC/Filters]
[/W3SVC/1]
[/W3SVC/2]
[/W3SVC/3]
C:\Inetpub\AdminScripts>
I need to get the last line ([/W3SVC/3]) extract the 3 and add 1 to it. In other words the result of the batch execution would output 4
I need something that will be smart enough to handle situations where the output is something like this aswell
C:\Inetpub\AdminScripts>ad
[/W3SVC/Info]
[/W3SVC/Filters]
[/W3SVC/1]
I am fairly certain this can be done with FOR but I am not certain on how to implement it
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
possibly... (untested)
=====================
for /f "tokens=1-3 delims=/]" %%a in ('adsutil ENUM /P W3SVC') do (
set /a NUMBER=%%c
)
set /a TOTAL=NUMBER+1
=====================
-Brian