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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...