Splunk Search

Combine stats across multiline events

hulahoop
Splunk Employee
Splunk Employee

How can I get stats by author if I have multiline events like the below?

Project: /a/b/c
  loc=100 author=aaa@foo.com
  loc=100 author=bbb@foo.com
  loc=100 author=ccc@foo.com

Project: /a/b/c
  loc=200 author=aaa@foo.com
  loc=200 author=ccc@foo.com
  loc=200 author=ddd@foo.com

Given the 2 events above, am looking for a results table like this:

Project   Author         Total Lines of Code (loc)
-------------------------------------------------
/a/b/c    aaa@foo.com    300
          bbb@foo.com    100 
          ccc@foo.com    300
          ddd@foo.com    200
Tags (3)
0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

You could do something like this:

... | rex "Project:\s+(?<project>\S+)" | rex max_match=0 "(?<loc_author>loc=\d+\s+author=\S+)" | mvexpand loc_author | rex field=loc_author "loc=(?<loc>\d+)\s+author=(?<author>\S+)" | stats sum(loc) by project author

Make sure that doesn't clash with a potentially auto-extracted first set of loc/author fields.

View solution in original post

martin_mueller
SplunkTrust
SplunkTrust

You could do something like this:

... | rex "Project:\s+(?<project>\S+)" | rex max_match=0 "(?<loc_author>loc=\d+\s+author=\S+)" | mvexpand loc_author | rex field=loc_author "loc=(?<loc>\d+)\s+author=(?<author>\S+)" | stats sum(loc) by project author

Make sure that doesn't clash with a potentially auto-extracted first set of loc/author fields.

hulahoop
Splunk Employee
Splunk Employee

Thank you, Martin! mvexpand is magical. 🙂

0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

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