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
Super Champion

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!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

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