Splunk Search

Combine Multiple Fields

JaysonD123
Explorer

Hello,

 

I'm relatively new to Splunk. I have multiple fields with different naming schemes that have different  or identical values. Here's an example:

 

hash=yj843yj387hfhjf723hjf47hnf29nf

hashes=xmv98svmd89djmfv98jvkfj9jm

Hashes=n9nuevur9vv9v8fj0fefjeffjv9ejve8

sha1_hash=84hmrh42mfu2hmxufxfmu28

src_hash=2xf9mf4jmfijjumrfx2r9mjfru2mjrm9j

 

name=jayson

Src_name=jayson

NAME=jayson

SubjectUserName=jayson

 

I'm trying to make a query checks if there is a field that contains the word "hash" or "name" and tables it out. Here's what I have so far:

 

| eval Hash=hash, Hash=hashes

| foreach Hash* [eval Hash=mvappend(Hash, "")]
| eval Name=name, Name=Src_name
| foreach Name* [eval Name=mvappend(Name, "")
| table Name Hash



I need to table the results from any field that has the word "hash" or "name" in it. Also is there a way to simplify this?

Labels (2)
1 Solution

bowesmana
SplunkTrust
SplunkTrust

@JaysonD123 

Good to see that you're diving in the deep end with the use of foreach, which is not such a commonly used command, but a very powerful one...

You're on the right track, but your initial assignments Hash=hash, Hash=hashes, will not do much good as it's making the field Hash equal to the field hashes, regardless of what hash is.

Fields are case sensitive, so from your sample data, you need to be doing a case insensitive comparison of the field name to either name or hashes. This runnable example shows you how to do this, also using foreach, but using the <<MATCHSTR>> and <<FIELD>> elements of foreach, which are crucial to getting this to work.

| makeresults
| eval hash="yj843yj387hfhjf723hjf47hnf29nf"
| eval hashes="xmv98svmd89djmfv98jvkfj9jm"
| eval Hashes="n9nuevur9vv9v8fj0fefjeffjv9ejve8"
| eval sha1_hash="84hmrh42mfu2hmxufxfmu28"
| eval src_hash="2xf9mf4jmfijjumrfx2r9mjfru2mjrm9j"
| eval name="jayson"
| eval Src_name="jayson"
| eval NAME="jayson"
| eval SubjectUserName="jayson"
| eval anotherField1="Something else", anotherField2="another"
| foreach * [ eval N=if(match("<<MATCHSTR>>","(?i)name"), mvappend("<<MATCHSTR>>=".<<FIELD>>, N), N),  H=if(match("<<MATCHSTR>>","(?i)hash"), mvappend("<<MATCHSTR>>=".<<FIELD>>, H), H)]

All you need is the  foreach statement. I have made it foreach *, so all field names can be checked. The H and N fields end up with a multi value field with fieldName=value for each of the matching fields.

Edit the mvappend as required.

 

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

@JaysonD123 

Good to see that you're diving in the deep end with the use of foreach, which is not such a commonly used command, but a very powerful one...

You're on the right track, but your initial assignments Hash=hash, Hash=hashes, will not do much good as it's making the field Hash equal to the field hashes, regardless of what hash is.

Fields are case sensitive, so from your sample data, you need to be doing a case insensitive comparison of the field name to either name or hashes. This runnable example shows you how to do this, also using foreach, but using the <<MATCHSTR>> and <<FIELD>> elements of foreach, which are crucial to getting this to work.

| makeresults
| eval hash="yj843yj387hfhjf723hjf47hnf29nf"
| eval hashes="xmv98svmd89djmfv98jvkfj9jm"
| eval Hashes="n9nuevur9vv9v8fj0fefjeffjv9ejve8"
| eval sha1_hash="84hmrh42mfu2hmxufxfmu28"
| eval src_hash="2xf9mf4jmfijjumrfx2r9mjfru2mjrm9j"
| eval name="jayson"
| eval Src_name="jayson"
| eval NAME="jayson"
| eval SubjectUserName="jayson"
| eval anotherField1="Something else", anotherField2="another"
| foreach * [ eval N=if(match("<<MATCHSTR>>","(?i)name"), mvappend("<<MATCHSTR>>=".<<FIELD>>, N), N),  H=if(match("<<MATCHSTR>>","(?i)hash"), mvappend("<<MATCHSTR>>=".<<FIELD>>, H), H)]

All you need is the  foreach statement. I have made it foreach *, so all field names can be checked. The H and N fields end up with a multi value field with fieldName=value for each of the matching fields.

Edit the mvappend as required.

 

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!

SOK it to Me: Top 3 Benefits of Using Splunk Operator on Kubernetes that’ll Make ...

    Thursday, July 9, 2026  |  11:00AM–12:00PM PDT Duration: 1 hour (includes Q&A) Managing can feel like a ...

Upgrade Prep for 10.4, Network Observability Deep Dives, and More from Splunk Lantern

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

Splunk Developer Day announcements: AI agents, MCP tools, Forecasting, and Custom ...

Splunk Developer Day was packed with product and platform updates for developers building in the AI ...