Splunk Search

Rename field by using one of multiple wildcards

maartendhondt
Explorer

I have a query that counts by source and leaves me with fields that are named like /logs/containers/3198058471-5mdkn_ef22f06f3462c74029d23d3ef6d5c765ecd41c2f86f796b074ea2e2de83bf4bd.log.

I would like to rename my fields to whatever comes after /logs/containers/ and before the _.

I am looking for something like this:

| rename /logs/containers/*_* as *
Tags (2)
0 Karma
1 Solution

kamlesh_vaghela
SplunkTrust
SplunkTrust

@maartendhondt

Can you please try this?

YOUR_SEARCH | foreach "/logs/containers/*" [ eval field=mvindex(split("<<MATCHSTR>>","_"),0), {field}='<<FIELD>>' ] | fields - "/logs/containers/*", field

My Sample Search:

| makeresults 
| eval "/logs/containers/3198058471-5mdkn_ef22f06f3462c74029d23d3ef6d5c765ecd41c2f86f796b074ea2e2de83bf4bd.log"="aaa" 
| foreach "/logs/containers/*" [ eval field=mvindex(split("<<MATCHSTR>>","_"),0), {field}='<<FIELD>>' ] | fields - "/logs/containers/*", field

Thanks

View solution in original post

kamlesh_vaghela
SplunkTrust
SplunkTrust

@maartendhondt

Can you please try this?

YOUR_SEARCH | foreach "/logs/containers/*" [ eval field=mvindex(split("<<MATCHSTR>>","_"),0), {field}='<<FIELD>>' ] | fields - "/logs/containers/*", field

My Sample Search:

| makeresults 
| eval "/logs/containers/3198058471-5mdkn_ef22f06f3462c74029d23d3ef6d5c765ecd41c2f86f796b074ea2e2de83bf4bd.log"="aaa" 
| foreach "/logs/containers/*" [ eval field=mvindex(split("<<MATCHSTR>>","_"),0), {field}='<<FIELD>>' ] | fields - "/logs/containers/*", field

Thanks

Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...