Splunk Search

How can I extract a field value from a folder name?

jamesvz84
Communicator

I have a file that Splunk monitors stored in F:/xxx/2014/file.csv. Is there any way to dynamically take the 2014 folder and assign the 2014 value to a "report_year" field for each event? (Folder may be any year, not just 2014)

0 Karma

aholzer
Motivator

Yes, use the rex command with the "source" as the field. Like so:

<base search> | rex field=source "(.*/){2}(?P<year>\d+)/"

This will dinamically look for the second forward slash "/" and then capture all digits in a field labeled year.

Hope this helps

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...