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
Legend

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
Revered Legend

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!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...