Splunk Search

How to count all occurrences of certain strings from subsearch results?

lessard
Engager

I have text that is not well formatted, and I'm looking for occurrences of some text. In one spot, the text is easy to identify, so I'm identifying the text, and then finding all instances of that text in other areas of the log.

I currently have the following search working nicely to show me the lines I want to look at.

index=my_index [search index=my_index "[mysearch=" | rex "[mysearch=(?<mytext>[^\]]*)" | makemv delim="," mytext | rename mytext to query | fields query]

Given text like such:

[mysearch=111,222,333] Some random text and a row I want
[mysearch=444] Some random text and a row I want
[some silly line] this would not appear with the above query
[some other log]  Text that has 111 and 444 and a row I want but also numbers I do not want to count 1 2 3 555 
[some silly line] this would not appear with the above query 555 4 2 3 4 8 4444

My search pulls the correct three rows out. Now I'd like to count the occurrences of 111 and 222 and 333 and 444. For the above three lines giving me 2 counts for 111 and 444, and 1 count for 222 and 333, but I can't figure out how to get something like "stats count by mytext" to work.

Any suggestions?

Thanks.

Tags (3)
0 Karma

javiergn
SplunkTrust
SplunkTrust

Try this:

| your search here
| rex max_match=0 "=?(?<mytext>\d+)\,?"
| mvexpand mytext
| stats count by mytext

This is the output I'm getting based on the example given above:

mytext  count
111     2
222     1
333     1
444     2 

lessard
Engager

Thanks! Worked perfectly!
edit: I thought this was working, but the counts were far lower than I expected. I've modified the original question to show where I think some of the road bumps occur

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 ...