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 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 ...