question

bbaker avatar image
bbaker asked bbaker posted

String Types

I have a table that contains a colum which can be either a text string or a numeric value.  I need an IF statement that can check to see which string type the query returned.

 

 

Neighbor        V     AS MsgRcvd MsgSent  InQ OutQ Up/Down   State/PfxRcd

10.22.50.2      4      2     201     189    0    0 02:03:47           602

10.22.50.3      4      3     194     210    0    0 02:03:48           603

10.22.50.4      4      4     199     213    0    0 02:03:18           603

10.22.50.254    4  65535     201     193    0    0 02:03:07           603

10.22.51.129    4   1112     146     201    0    0 00:00:20  Connect

10.22.51.130    4   1112     148     205    0    0 00:00:20  Connect

 

Looking at the last column, if the response contains a number, I need the test to pass.  If it contains text, it should fail.  I'll be sticking this inside a for loop so that any text response on any line will trigger a failure.  I beliece I have this all figured out except the syntax for the IF statement.

 

iTestresponse map
10 |950

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

1 Answer

·
PaulD avatar image
PaulD answered PaulD posted

You can take advantage of the interpreter's "string" command to find out if a value is numeric or not.  For example

 

 

foreach    entry [ <query to get all values> ]
   if      [string is integer $entry]
      then
           <handle integers here>
      else
           <handle non-integers here>


 

 

 

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.