Splunk Search

Change order of comma separated names

Kat456
Engager

I have a list of comma separated names (lastname, firstname) that I need to reverse. So "Smith, Suzy" becomes "Suzy Smith".  What's the easiest way to do this? 

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @Kat456 ,

I suppose that you ingested these data from the csv file in Splunk.

When you have them in Splunk you cas have in the order you like:

index=your_index
| table firstname lastname

Ciao.

Giuseppe

0 Karma

yuanliu
SplunkTrust
SplunkTrust

When you say "a list of", I assume that this list is in a field that is single-valued in each event.  Is this correct?  Assuming yes, and assuming a field name of fullname, you can do

 

| eval fullname = trim(split(fullname, ","), " ")
| eval fullname = mvjoin(mvreverse(fullname), " ")

 

Here is an emulation you can run and compare with real data

 

| makeresults
| fields - _*
| eval fullname = "Smith, Suzy"
``` data emulation above ```
| eval fullname = trim(split(fullname, ","), " ")
| eval fullname = mvjoin(mvreverse(fullname), " ")

 

Output is

fullname
Suzy Smith

Hope this helps

Tags (1)

Kat456
Engager

This worked perfectly. Thank you!

0 Karma
Get Updates on the Splunk Community!

Upcoming Webinar: Unmasking Insider Threats with Slunk Enterprise Security’s UEBA

Join us on Wed, Dec 10. at 10AM PST / 1PM EST for a live webinar and demo with Splunk experts! Discover how ...

.conf25 technical session recap of Observability for Gen AI: Monitoring LLM ...

If you’re unfamiliar, .conf is Splunk’s premier event where the Splunk community, customers, partners, and ...

A Season of Skills: New Splunk Courses to Light Up Your Learning Journey

There’s something special about this time of year—maybe it’s the glow of the holidays, maybe it’s the ...