Splunk Search

regex to extract date from the file name

athorat
Communicator

Hi

we are using fs_notification and monitoring a specific path.
I have a field called path which has the following values.
Now I have to extract the date from the name of the file which is 2016-03-28 for the following files and then do a count of those values.

    /ubidata/axway/JourneyData/AAA_NA_70_2016-03-28-03-30-07_353466071554972_NA_0_0.zip
    /ubidata/axway/JourneyData/AAA_NA_70_2016-03-28-00-47-08_353466071286872_1HGCR2F5XDA159398_0_0.zip
    /ubidata/axway/JourneyData/AAA_NA_709_2016-03-28-23-38-13_353466070336173_5J6YH28776L027013_0_0.zip
    /ubidata/axway/JourneyData/AAA_NA_709_2016-03-28-23-11-04_353466070738055_JHMES96664S000240_0_0.zip
    /ubidata/axway/JourneyData/AAA_NA_709_2016-03-28-22-23-29_353466070290842_1FTRW12557FB57292_0_0.zip
    /ubidata/axway/JourneyData/AAA_NA_709_2016-03-28-20-36-26_354235059078372_1GNDV23LX6D194324_0_0.zip
    /ubidata/axway/JourneyData/AAA_NA_709_2016-03-28-20-31-06_354235059637177_JTDBR32E170131585_0_0.zip
    /ubidata/axway/JourneyData/AAA_NA_709_2016-03-28-20-27-01_354235059626014_2GKFLSE39D6131090_0_0.zip
    /ubidata/axway/JourneyData/AAA_NA_709_2016-03-28-20-14-59_354235059651772_3FAHP06Z48R221560_0_0.zip
    /ubidata/axway/JourneyData/AAA_NA_709_2016-03-28-20-08-00_354235057942819_1G1ZT64885F132289_0_0.zip
    /ubidata/axway/JourneyData/AAA_NA_709_2016-03-28-19-50-45_354235058343207_JHLRM3H51CC010877_0_0.zip
    /ubidata/axway/JourneyData/AAA_NA_709_2016-03-28-19-20-32_353466070121963_1J4FT28B19D178678_0_0.zip
    /ubidata/axway/JourneyData/AAA_NA_709_2016-03-28-18-23-14_354235059577712_5FNYF28407B037209_0_0.zip
Tags (1)
0 Karma

sundareshr
Legend

This should get you the date

rex "_(?<date>\d{4}-\d{2}-\d{2})-"
0 Karma

niemesrw
Path Finder

I'm definitely not the best with regex, but maybe something like this?

rex field=path "\_\w+\_(?<date>\w+-\w+-\w+)"
0 Karma

athorat
Communicator

Sample Event :

Fri Apr  8 18:20:42 2016 action=add, path="/ubidata/axway/JourneyData/AAA_NA_712_2016-03-28-21-19-03_354235057942819_1G1ZT64885F132289_0_0.zip", isdir=0, size=18443, gid=0, uid=0, modtime="Fri Apr  8 18:20:41 2016", mode="rw-r--r--", hash=
0 Karma
Get Updates on the Splunk Community!

Splunk Answers Content Calendar, June Edition

Get ready for this week’s post dedicated to Splunk Dashboards! We're celebrating the power of community by ...

What You Read The Most: Splunk Lantern’s Most Popular Articles!

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...