Splunk Search

Need string minus last 2 characters

rachelneal
Path Finder

I am trying to set a field to the value of a string without the last 2 digits. For example:

Hotel=297654 from 29765423
Hotel=36345 from 3624502

I tried rtrim but docs say you must know the exact string you're removing, mine are different every time. I also tried substr but the length is not constant from 1st character and using -2 like substr(Field, -2) returns the last 2 characters...the part I want to throw away.

Was trying something like rtrim(Field,substr(Field,-2) but can't get that to work.

Suggestions? - THANKS

Tags (1)
0 Karma
1 Solution

_d_
Splunk Employee
Splunk Employee

This may do it:

<your_search_here> | eval myfield = substr(myfield, 1, len(myfield)-2)

d.

-
please upvote if you find this answer useful

View solution in original post

_d_
Splunk Employee
Splunk Employee

This may do it:

<your_search_here> | eval myfield = substr(myfield, 1, len(myfield)-2)

d.

-
please upvote if you find this answer useful

Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...