Splunk Search

How to find last value of multivalue field (Split and mvindex)?

Krishna_Sridhar
New Member

I have a URL field and need to find the last word (split by "/")

Ex:
URL 1: xxx/yyy/ServiceName
URL 2 : aaa/bbb/ccc/ddd/serviceName

I tried mvindex(split(URL, "/"),5) to get the service name, but the index "5" shouldn't be static, number of sub folders vary from URL to URL. Need help in identifying the last index on the URL.

Thanks in advance.

Labels (1)
Tags (3)
0 Karma
1 Solution

emiller42
Motivator

You can count from the end by using negative values. mvindex(split(URL,"/"),-1) will get you what you want.

View solution in original post

emiller42
Motivator

You can count from the end by using negative values. mvindex(split(URL,"/"),-1) will get you what you want.

neerajs_81
Builder

How do you calculate the inverse i.e. the 1st value  assuming its not static ?
For example: Consider a multi-value field with values like this

001,002, 003, 004
001,002,003,005,006

001 is the 1st value to occur in time sequence followed 002..003 in sequence.  Think of it like different status changes of a ticket. 

If i do a mvindex(field,-1), it gives me 001 i.e. the first/earliest status to occur .  What index should I specify of getting the last value in sequence  as in 004 and 006 respectively.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Assuming filed is a multivalue field, -1 will give you the last value.

Krishna_Sridhar
New Member

Thank you!

0 Karma
Get Updates on the Splunk Community!

Earn a $35 Gift Card for Answering our Splunk Admins & App Developer Survey

Survey for Splunk Admins and App Developers is open now! | Earn a $35 gift card!      Hello there,  Splunk ...

Continuing Innovation & New Integrations Unlock Full Stack Observability For Your ...

You’ve probably heard the latest about AppDynamics joining the Splunk Observability portfolio, deepening our ...

Monitoring Amazon Elastic Kubernetes Service (EKS)

As we’ve seen, integrating Kubernetes environments with Splunk Observability Cloud is a quick and easy way to ...