Splunk Search

Regex merge match to single name

webshan
Engager

HI I have 2 log files(access log file and custom log file) with data as given below.

LogFile1 (access log)
GET /login HTTP/1.1 302 - 1234 800

Where 1234 is USERID

LogFile2 (custom file)
DATA EVENT->1234:loginTime SOME EVENT DESC

I want to get a report like below:

USER ACCESS_COUNT CUSTOM_COUNT
1234 4 5
2345 6 7
4567 7 8

I tried

source=access.log OR source=customlog.log QueryForAccess OR QueryForCustom | rex "(?i).*?\->(?P<USER>\d+)(?=:)|(?i)^(?:[^\-]*\-){5}\s+(?P<USER>[^ ]+)"
|stats count(eval(searchmatch(QueryForAccess))) as ACCESS_COUNT count(eval(searchmatch(QueryForCustom))) as CUSTOM_COUNT  by USER

But I got cant use same pattern. I changed rex fields to USER1 & USER2 and stats as USER1,USER2 but could not get any result.

How do I ensure that I get report of USER who is in either access log or in custom log & their counts??

Thanks

Tags (4)
0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

I assume you are trying to have one rex pull a field from two different sourcetypes?

Consider two rex calls, something like this:

... | rex "some pattern" | rex "some other pattern" | ...

If you use different field names in each rex you can then merge them into one field using a combination of eval and a test for null/invalid values. However, using the same field name in both rex's should work as well. Just make sure the first pattern does not match the second sourcetype and vice versa.

View solution in original post

martin_mueller
SplunkTrust
SplunkTrust

I assume you are trying to have one rex pull a field from two different sourcetypes?

Consider two rex calls, something like this:

... | rex "some pattern" | rex "some other pattern" | ...

If you use different field names in each rex you can then merge them into one field using a combination of eval and a test for null/invalid values. However, using the same field name in both rex's should work as well. Just make sure the first pattern does not match the second sourcetype and vice versa.

webshan
Engager

Thanks for inputs. I tried as below and it worked for me.

source=customlog.log QueryForCustom | rex "(?i).*?\->(?P<USER>\d+)(?=:)" |  stats count(eval(searchmatch(QueryForCustom))) as CUSTOM_COUNT  by USER
| JOIN type=inner USER [SEARCH source=access.log OR QueryForAccess | rex "(?i)^(?:[^\-]*\-){5}\s+(?P<USER>[^ ]+)" |stats count(eval(searchmatch(QueryForAccess))) as ACCESS_COUNT by USER ] | USER, CUSTOM_COUNT, ACCESS_COUNT
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...

SPL2 Deep Dives, AppDynamics Integrations, SAML Made Simple and Much More on Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...