Getting Data In

How can I remove a string from a source name?

navins007
New Member

below is my search

source=abc-server

I want to trim "-server"

and I tried this

| eval source=trim("abc-server", "-server")

did not work any idea how to do this?

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi navins007,
the easiest way is a regex:

| rex field=source "(?<source>[^-]*)-server"

or, if the string before "-server" has a fixed lenght

| eval source=substr(source,1,string_lenght)

but regex is better and more efficient!
Bye.
Giuseppe

navins007
New Member

thanks cusello and kamlesh, i will try your suggestions.

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

Hi

Can you please try below search?

YOUR_SEARCH | rex field=source "(?<source>.*)\-.*"

Thanks

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...