Splunk Search

extract file name from the source using rex

raghunand
Explorer

My regex to extract a file from a source field works: [^/]*(?=($|\?))

For example:

/nfs/tibcosoftware/Splunk/impactAnalysis/freight/TestProject/1.0-SNAPSHOT-31/defaultVars/folder/defaultVars.substvar

returns
defaultVars.substvar
See here - http://www.regexr.com/3bvp8

But when I try using this in the rex search command, I cannot get the same result. Why?

sourcetype=tibco_ia | rex field=source  "(?<iaFileName>.*)[^/]*(?=($|\?))" | table iaFileName

This returns full file path - /nfs/tibcosoftware/Splunk/impactAnalysis/freight/TestProject/1.0-SNAPSHOT-31/defaultVars/folder/defaultVars.substvar, but I expected to get defaultVars.substvar

Please advise?

0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

Try something like this

sourcetype=tibco_ia | rex field=source ".*/(?<iaFileName>.*)$" | table iaFileName

View solution in original post

somesoni2
SplunkTrust
SplunkTrust

Try something like this

sourcetype=tibco_ia | rex field=source ".*/(?<iaFileName>.*)$" | table iaFileName

varad_joshi
Communicator

This is the simplest answer on this query so far.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...