Splunk Search

How can I output only the first n characters of field value?

JohnEGones
Communicator

HI people,

I want from a query to only print out the first n-characters of the field value. So:

 

index=someIndex sourcetype=someNetworkDevice
| stats count by someField

 

 

The output goes:

 

someField

this is a strong value 1
this is a string value 1a
this is a string value 2
some other string value 1
some other string value 1a
some other string value 2
this is yet another string value 1
this is yet another string value 1a

etc.

 

 

I want to pull out say the first 10 characters in each row:

 

this is a
this is a
this is a
some other
some other
some other
this is yet
this is yet 

etc

 

Labels (3)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

HI @JohnEGones ,

I have some problem to understand why you're doing this!

Anyway, you can use eval substr to take only the first n chars of a field:

index=someIndex sourcetype=someNetworkDevice
| stats count by someField
| eval someField=substr(someField,1,10)

as you san see at https://docs.splunk.com/Documentation/Splunk/9.1.0/SearchReference/TextFunctions#substr.28.26lt.3Bst...

Ciao.

Giuseppe

View solution in original post

0 Karma

JohnEGones
Communicator

HI Giuseppe,

Nope you got it. Like when it's quick and easy. 

 

Thanks.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @JohnEGones ,

good for you, see next time!

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated 😉

0 Karma

gcusello
SplunkTrust
SplunkTrust

HI @JohnEGones ,

I have some problem to understand why you're doing this!

Anyway, you can use eval substr to take only the first n chars of a field:

index=someIndex sourcetype=someNetworkDevice
| stats count by someField
| eval someField=substr(someField,1,10)

as you san see at https://docs.splunk.com/Documentation/Splunk/9.1.0/SearchReference/TextFunctions#substr.28.26lt.3Bst...

Ciao.

Giuseppe

0 Karma
Get Updates on the Splunk Community!

Technical Workshop Series: Splunk Data Management and SPL2 | Register here!

Hey, Splunk Community! Ready to take your data management skills to the next level? Join us for a 3-part ...

Spotting Financial Fraud in the Haystack: A Guide to Behavioral Analytics with Splunk

In today's digital financial ecosystem, security teams face an unprecedented challenge. The sheer volume of ...

Solve Problems Faster with New, Smarter AI and Integrations in Splunk Observability

Solve Problems Faster with New, Smarter AI and Integrations in Splunk Observability As businesses scale ...