Splunk Search

Count number of occurrences in more than one field

tnkoehn
Path Finder

I have two fields, Inbound and Outbound. Each of these fields can contain a group (sometimes they're null). I need to get a count of the groups if they match a specific regex (i.e. must start with ATT, MCI or QST). The problem is that a valid group can be in either field, and certain groups can be both an Inbound and Outbound group. Below is a small example of some events:

Inbound   Outbound
OMA01002  QST_0960
ATT_0002  QST_0965
OMA01000  QST_0960
ATT_0004
ATT_0119  ATT_0002 
MCI_0023 
QST_0960  ATT_0407
          ATT_0119
ATT_0004  RG17

As you can see in the example ATT_0002, ATT_0119 and QST_0960 can be an Inbound or Outbound group. But I don't care about what group it is, I only care about the counts for each group. So the results I need are:

Group      Count
ATT_0002   2
ATT_0004   2
ATT_0119   2
ATT_0407   1
MCI_0023   1
QST_0960   3
QST_0965   1

I'm not sure how to do this or if it's possible without two searches. Below is a simplified search that is kind of a starting point.

search * | fields Inbound Outbound
         | where match(Inbound, "^(ATT|MCI|QST)") OR match(Outbound, "^(ATT|MCI|QST)") 
         | do amazing counting stuff here

Hope this makes sense. Thanks for any help.

Tags (1)
0 Karma
1 Solution

gkanapathy
Splunk Employee
Splunk Employee
... | eval Group=mvappend(Inbound,Outbound) | stats count by Group

View solution in original post

gkanapathy
Splunk Employee
Splunk Employee
... | eval Group=mvappend(Inbound,Outbound) | stats count by Group

tnkoehn
Path Finder

So simple. You guys make me feel like an idiot, but it's precisely what I need. Thanks so much!

0 Karma

surekhasplunk
Communicator

Hi @gkanapthy, and @tnkoehn

I have similar requirement but instead of | where match(Inbound, "^(ATT|MCI|QST)") OR match(Outbound, "^(ATT|MCI|QST)")
i have
| where match(Inbound, "abc") OR match(Outbound, "def")
now how should i achieve this

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...