Getting Data In

Truncate the log description after n words.

RSS_STT
Explorer

How can i Truncate the log description after 20 words in splunk and store in new field.

Labels (1)
0 Karma

batabay
Path Finder

Hello,

You can try this.

| makeresults 
| eval test = "somestring1somestring2somestring3" 
| eval new_field = if(len(test)>20,substr(test,20,len(test)),null())
0 Karma

RSS_STT
Explorer

i need to truncate the string based on word count, not based on character count.

it should save truncated string (start to 25 words) into new fields.

Current which you have provided doing on character count basis.

0 Karma

batabay
Path Finder

Okay Than, We can use regex. Can you try this ? 

| makeresults 
| eval description = "somestring1 somestring2 somestring3 somestring4 somestring5" 
| rex field=description "(?<new_field>^\S+(?:\S+\s+){20}\S+)" 
| eval new_field_replaced = replace(description,new_field,"")
| eval description = replace(description,new_field,"")

 

 

RSS_STT
Explorer

Looking good.  But this regex not handling the special character and digit. for example date 05/0/:2024 10:11:56.000 EST

0 Karma

batabay
Path Finder

I couldn't exactly understand what you're not doing with the timestamp. There are many different ways to extract the timestamp from the log. If you want to capture this field additionally, you can use \S+\s\S+.

There is example regex;

^\S+\s+\S+\s\w+\s(\S+(?:\S+\s+){1}\S+)

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...