Splunk Search

How to use substr to extract the first character of a string and keep all characters up until the first space character?

bhicks32
Explorer

I have a string nadcwppcxicc01x CPU Usage has exceeded the threshold for 30 minutes &I where I would like to create a new column and extract from the string where it would show nadcwppcxicc01x only. I know this would be possible using substr(tablename,1,15), however, I have other strings that differ in length.

Any help would be appreciated!

0 Karma
1 Solution

jbjerke_splunk
Splunk Employee
Splunk Employee

Hi bhicks32

Use the "rex" command. It's much more flexible than substr.

For this string it would look like this:

 YOURSEARCH | rex field=YOURFIELD "(?<NEWFIELD>[^\s]+)"

If you are not entirely familiar with regex I can recommend this site as a reference:

http://regexr.com/

If this works, please mark as answered.

j

View solution in original post

0 Karma

jbjerke_splunk
Splunk Employee
Splunk Employee

Hi bhicks32

Use the "rex" command. It's much more flexible than substr.

For this string it would look like this:

 YOURSEARCH | rex field=YOURFIELD "(?<NEWFIELD>[^\s]+)"

If you are not entirely familiar with regex I can recommend this site as a reference:

http://regexr.com/

If this works, please mark as answered.

j

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 ...