question

Shubhagata avatar image
Shubhagata asked lakshminarayana answered

how can I pick a word from string variable

Could you please suggest if there is any way to pick a single word for comparision from command output string. Below is the command and its output. VS1#show ip bgp vpnv4 vrf 40 neighbors 172.17.7.2 | in BGP state BGP state = Established, up for 3w3d I have applied analysis rule to store the output in a variable 'bgpState' using regEx :: ^\s+BGP state =\s+([^\r\n]+)$ For this particular example ablove 'bgpState' variable contains 'Established, up for 3w3d' Is there any way to pick only word 'Established' from 'bgpState' variable. I want to apply 'if' structure as if bgpState == "Established" This is required because BGP state may be down/active and also up/down for hours/days/weeks Thank you in advanced.
iTestVariablesregex
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

lakshminarayana avatar image
lakshminarayana answered
Select the **BGP state** value and add a **Quick Analysis Rule** as shown in the below screenshot. ![alt text][1] [1]: /storage/temp/3777-analysisrule.jpg Here the variable $value stores the state of BGP and compares it with the string "Established". If the BGP state is otherthan Established, this analysis rule gets fail.

analysisrule.jpg (74.6 KiB)
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sai_kiran avatar image
sai_kiran answered
This is another way to achieve this. We could also create a pattern response map and create a query for the "Established" word, then using this query we could store the word in a variable as Analysis rule >Query against the response data >store the extracted data in a variable. Attached is the response map for your reference[link text][1]. In order to use this response map go to step properties of the required step in the test case, then Other post processing > Select the Expected Response map option > Browse the Response map. Thanks! [1]: /storage/temp/3728-response.ffrm

response.ffrm (2.4 KiB)
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sai_kiran avatar image
sai_kiran answered ericnute edited
Could you please try with the following regular expression ^BGP state =\s+(\w+), up for\s+(\S+)*
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.