Splunk Search

How to capture the substring of a dynamic multivalued field?

GaryZ
Path Finder

I am looking to create an acronym from a dynamic string, by capturing the first letter of each broken substring

How do I write the script, so I can capture whatever number of substrings gets generated from the original string?

 

 

ie. "Hello_World_Look_At_Me" => "HWLAM"

"Hello_World" => "HW"

 

I'm thinking of doing the following, but this seems to be pretty lengthy.  Would like to know if there's a more efficient way of getting this done.

| eval txt1 = "Hello_World_Look_At_Me"

| eval tmp = split(txt1, "_")

| eval new_word = substr(mv_index(tmp,1), 1) + ...

 

 

Labels (5)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Assuming words are always made of alphabetic letters, try something like this

| rex max_match=0 field=txt1 "(?<initial>[a-zA-Z])[a-zA-Z]*_?"
| eval new_word=mvjoin(initial,"")

View solution in original post

GaryZ
Path Finder

Thanks!!! @ITWhisperer 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Assuming words are always made of alphabetic letters, try something like this

| rex max_match=0 field=txt1 "(?<initial>[a-zA-Z])[a-zA-Z]*_?"
| eval new_word=mvjoin(initial,"")
Get Updates on the Splunk Community!

Splunk Answers Content Calendar, June Edition

Get ready for this week’s post dedicated to Splunk Dashboards! We're celebrating the power of community by ...

What You Read The Most: Splunk Lantern’s Most Popular Articles!

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

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...