Splunk Search

How to trim values from results

Path Finder

Hi, We are looking to have my file name more readable and that being said FIlename looks like below and need to trim last 8 spaces.

Below is format my file name looks like and needs to display as data_20130701105312.txt and data_list2

data_20130701105312.txt a s o r team_1 ssh 0 *
data_list2 b s o r team_2 ssh 0 *


0 Karma

Esteemed Legend

Your description is confusing to me but if (and that is a HUGE "if") you are asking for a RegEx to consider the flinename as all the first of the non-whitespace-strings separated by spaces (of which there are always 8), then you can use this:

| rex "^(?<filename>\S+)"

Splunk Employee
Splunk Employee

@splunker9999 - Did one of the answers below help provide a solution your question? If yes, please click “Accept” below the best answer to resolve this post and upvote anything that was helpful. If no, please leave a comment with more feedback. Thanks.

0 Karma


If none of those answers worked for you, then I think we need a clearer explanation. You say 8 spaces, but I think you may be referring to 8 values after the filename? If so, then somesoni2's first suggestion should pull the filename correctly.

| rex field=Filename "(?<Filename>\S+)(\s+\S+){8}$"
0 Karma

Revered Legend

How about this?

your base search | rex field=FIlename "(?<Filename>\S+)(\s+\S+){8}$"


your base search | rex field=FIlename "(?<Filename>\w+\.\w+)"


Here are two ways and there may be others.

... | eval fname=mvindex(split(Filename," "),0) | ...

... | rex field=Filename "(?<fname>[^\s]*)" | ...
If this reply helps you, Karma would be appreciated.
0 Karma

Path Finder

Thanks for this, but this would work if only one space exists in file name.

some of filenames has multiple spaces in between as below.

004 3400 date County name age1216.pdf
004 3000 date name.pdf
004 3200 date name
 This was the reason I am looking to do regex from backwards of FileName above,since last 8 spaces are constant for all of the files .

Can you please help us in doing regex which should check fileName from backwards and needs to exclude 8 spaces and give rest of the value as FileName

0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

WATCH NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If exploited, ...

Enter the Splunk Community Dashboard Challenge for Your Chance to Win!

The Splunk Community Dashboard Challenge is underway! This is your chance to showcase your skills in creating ...

.conf24 | Session Scheduler is Live!!

.conf24 is happening June 11 - 14 in Las Vegas, and we are thrilled to announce that the conference catalog ...