Splunk Search

Count occurrences of string and put them in table row wise?

Vivekmishra01
Explorer

I am trying to find few strings in my search query and count occurrences of them and I want to put them in a two column table. I am able to do it with stat command, but it's coming like string as column name and count in the row bwlow. Below is what I am using and what I ma getting.

 

 

 

index=<index> <search String > "Failed" | stats count AS Failed count(eval(searchmatch("Failed Acknowledged"))) AS "Failed Acknowledged" count(eval(searchmatch("UnexpectedException Caught"))) AS "UnexpectedException Caught" count(eval(searchmatch("NonRetryableException Caught"))) AS "NonRetryableException Caught"

 

 

 

However I want a result like below.

Vivekmishra01_0-1673363523720.png

Can anyone help? Thanks in advance.

Labels (3)
Tags (2)
0 Karma
1 Solution

GaetanVP
Contributor

Hello ! 

You could try this :

<your search> | transpose 0 column_name="Message" | rename "row 1" as Count

 

Good luck!

View solution in original post

FelixLeh
Contributor

Hi!
Is this accomplishing what you are looking for? (I assume you are working with untransformed Events here)

 

index=<index> <search String > "Failed" 
| eval Message = case(like(_raw,"%Failed Acknowledged%"),"Failed Acknowledged",like(_raw,"%UnexpectedException Caught%"),"UnexpectedException Caught",like(_raw,"%NonRetryableException Caught%"),"NonRetryableException Caught",true(),NULL)
| stats count by Message 

 

 If you want to add a line that sums up the total amount of events you can add the following:

 

| addtotals fieldname=count col=t labelfield=Message

 

0 Karma

GaetanVP
Contributor

Hello ! 

You could try this :

<your search> | transpose 0 column_name="Message" | rename "row 1" as Count

 

Good luck!

Get Updates on the Splunk Community!

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...

Index This | What goes away as soon as you talk about it?

May 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...

What's New in Splunk Observability Cloud and Splunk AppDynamics - May 2025

This month, we’re delivering several new innovations in Splunk Observability Cloud and Splunk AppDynamics ...