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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...