Splunk Search

How to trim values from results

splunker9999
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 *

Thanks

0 Karma

woodcock
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+)"

aaraneta_splunk
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

DalJeanis
SplunkTrust
SplunkTrust

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

somesoni2
SplunkTrust
SplunkTrust

How about this?

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

OR

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

richgalloway
SplunkTrust
SplunkTrust

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

splunker9999
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!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...