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!

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