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!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...