Splunk Search

How to extract a number of a string and check the count?

zoe
Path Finder

Hi, 

I have data like A-001, A-002, A-003.....

I would like to know how to extract the numbers from these strings: 001, 002, 003....so that I can generate an alert: every three batche (001, 004, 007) should be check.

Can someone help me with that? Thanks1

 

Regards,

Tong 

Labels (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @zoe,

if the format is always the same, you can use a regex like this:

index=your_index 
| rex "A-(?<number>\d+)"
| stats count BY number

you can test the regex at https://regex101.com/r/H1gAHF/1

Ciao.

Giuseppe

View solution in original post

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @zoe,

if the format is always the same, you can use a regex like this:

index=your_index 
| rex "A-(?<number>\d+)"
| stats count BY number

you can test the regex at https://regex101.com/r/H1gAHF/1

Ciao.

Giuseppe

0 Karma

zoe
Path Finder

Hi @gcusello ,

 

great! Thanks for the Tipp. It is exactly what I want. Many thanks!

 

Regards,

Tong

0 Karma

gcusello
SplunkTrust
SplunkTrust

hi @zoe,

good for you, see next time!

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated 😉

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...