Splunk Search

Search mutiple strings in logs and give count of respective string

ma_anand1984
Contributor

This is a followup question to

http://splunk-base.splunk.com/answers/61123/how-can-i-search-in-logs-for-mutiple-vaules-from-a-file

I learnt from above post that below is the query to search for mutiple strings.


source=snmp [|inputlookup severity | fields sev | rename sev as search | format]

Now, say if "foo", "bar", "blah" are present one per line in the lookup file "severity" under field "sev"

I want output like below


String Count
foo 5
bar 0
blah 3

How can we achieve that ?

1 Solution

jameshgibson
Path Finder

If I understand you correctly I did this in a rather inelegant way.

[your search] | rex field=sev "(?< f>foo)" | rex field=sev "(?<b>bar)" | rex field=sev "(?< bl>blah)" | eval strings=mvappend(f,NULL,b) | eval strings=mvappend(strings,NULL,bl) | mvexpand strings | stats count by strings

remove the spaces from the group names had to add them in to get it formating correctly. Hopefully someone can come up with something less awkward.

View solution in original post

jameshgibson
Path Finder

If I understand you correctly I did this in a rather inelegant way.

[your search] | rex field=sev "(?< f>foo)" | rex field=sev "(?<b>bar)" | rex field=sev "(?< bl>blah)" | eval strings=mvappend(f,NULL,b) | eval strings=mvappend(strings,NULL,bl) | mvexpand strings | stats count by strings

remove the spaces from the group names had to add them in to get it formating correctly. Hopefully someone can come up with something less awkward.

Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...