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!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...