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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...