Home / Microsoft / Microsoft DOS / How Extract Value between Parethesis
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] - (Bottom) Print
Author Topic: How Extract Value between Parethesis  (Read 444 times)
et_phonehome_2
Topic Starter
Rookie



Thanked: 1
Posts: 40


« on: November 09, 2009, 02:50:22 PM »

I need to extract the value between parentheses into a variable, I am not sure if there an easy way to do it.

STRING="QMNAME(testqm)   STATUS(Running)"

How can I get the following:
        var1=testqm
        var2=Running

This must be done in DOS only....

Thx
IP logged
Salmon Trout
Prodigy



Thanked: 501
Posts: 7,367

Computer: Specs
Experience: Guru
OS: Linux variant

1
« Reply #1 on: November 09, 2009, 03:38:54 PM »

I am hoping you mean NT family command prompt & not real MS-DOS...

1. Batch code

Code: [Select]
@echo off
set STRING="QMNAME(testqm)   STATUS(Running)"
for /f "tokens=1-4 delims=()" %%A in (%string%) do (
set var1=%%B
set var2=%%D
)
echo var1=%var1%
echo var2=%var2%

2. Output

Code: [Select]
var1=testqm
var2=Running
IP logged

gh0std0g74
Apprentice



Thanked: 37
Posts: 590


« Reply #2 on: November 09, 2009, 05:08:10 PM »

you can use vbscript
Code: [Select]
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
str1 = objArgs(0)
s=Split(str1,")")
For i=LBound(s) To UBound(s)
c=InStr(s(i),"(")
If c > 0 Then
WScript.Echo Mid(s(i),c+1)
End If
Next

save as test.vbs and on command line:
Code: [Select]
C:\test>cscript /nologo test.vbs "QMNAME(testqm)   STATUS(Running) BLAH(blah blah) "
testqm
Running
blah blah


what tool are you using to display running process status?
IP logged

billrich
Guest
« Reply #3 on: November 09, 2009, 05:29:39 PM »

I need to extract the value between parentheses into a variable, I am not sure if there an easy way to do it.

STRING="QMNAME(testqm)   STATUS(Running)"

How can I get the following:
        var1=testqm
        var2=Running

This must be done with Batch only....

Thx

There is no doubt that the batch solution is much better than the the VBS attempt above. Plus Et_Phone, the original poster, requested Batch.

VBS needs a board of its own.

p.s.:  VBS failed to assign testqm  and running to variables.

Casper failed to read instructions from  the original poster?
« Last Edit: November 09, 2009, 05:56:51 PM by billrich » IP logged
gh0std0g74
Apprentice



Thanked: 37
Posts: 590


« Reply #4 on: November 09, 2009, 06:21:58 PM »

There is no doubt that the batch solution is much better than the the VBS attempt above. Plus Et_Phone, the original poster, requested Batch.
no, you lost soul. the vbscript gets all text between parenthesis , no matter how many.  The batch only gets 2nd and 4th.

Quote
VBS needs a board of its own.
tell that to the administrator of the site.

Quote
p.s.:  VBS failed to assign testqm  and running to variables.
trivial trivial. you are always harping on trivial things. you sound like a woman to me.

Quote
Casper failed to read instructions from  the original poster?
the OP says DOS only, which i will assume he meant cmd.exe , so until he says "i don't need a vbscript", i will still keep posting vbscript solutions.. so what you gonna do about it ? go suck a thumb
« Last Edit: November 09, 2009, 08:42:28 PM by gh0std0g74 » IP logged

et_phonehome_2
Topic Starter
Rookie



Thanked: 1
Posts: 40


« Reply #5 on: November 10, 2009, 05:48:17 AM »

Salmon Trout, thanks for the response, I never realize that with DELIM, one can specify more than one expression.

Thanks to all for your response.  The reason I did not ask for VBScript, its because none of my servers have VB on it....
IP logged
gh0std0g74
Apprentice



Thanked: 37
Posts: 590


« Reply #6 on: November 10, 2009, 06:03:28 AM »

its because none of my servers have VB on it....
its vbscript, not VB.!! what windows server version are you running ?
IP logged

Pages: [1] - (Top) Print 
Home / Microsoft / Microsoft DOS / How Extract Value between Parethesis « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.084 seconds with 21 queries.