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!

Observe and Secure All Apps with Splunk

  Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

Splunk Decoded: Business Transactions vs Business IQ

It’s the morning of Black Friday, and your e-commerce site is handling 10x normal traffic. Orders are flowing, ...

Fastest way to demo Observability

I’ve been having a lot of fun learning about Kubernetes and Observability. I set myself an interesting ...