Splunk Search

Check for pure numeric field values or alphanumeric

AshimaE
Explorer

I have extracted a field using regex having the name push. I now have to classify all my rows into two categories based on whether push is all numeric or contains some alphabets also. Let it be divided into classes pure and mixed and given in a field class.
Any suggestions on how to do this since the numbers involved are too huge going upto 15-20 characters.How to fill in the class field for this statement.

Tags (2)
0 Karma

niketn
Legend

Hi Ashima, you can use isnum() evaluation function. Following is run-anywhere search.

| makeresults
| eval push="TestData123"
| eval class=if(isnum(push),"numeric","alpha")

PS: Above one will treat negative and decimal numbers also as numeric.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

niketn
Legend

@AshimaE, can you please test and confirm whether the suggested change works for you?

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi AshimaE,
try something like this

your_search
| rex field=push "(?<type_num>[0-9]*)"
| eval type=if(type_num=*,"Numeric","Alfanumeric")
| stats count by type

Bye.
Giuseppe

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...