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!

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...