Getting Data In

How to extract date from a field name in a csv file?

sc0tt
Builder

I'm struggling with extracting a date value from a field name in a csv file. I have a field named "Status for 2014-28-07". I want to extract the date portion of the field name in order to determine if the file was generated for the current date. I know that having a separate date field would simplify things, but this is how the file is generated.

What's the best way to do this?

Tags (2)
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

Take a look at this run-anywhere example:

| stats count | eval "Status for 2014-28-07" = "foo" | foreach "Status for 20*" [eval date = "20<<MATCHSTR>>"]

Result:

Status for 2014-28-07   date
foo                     2014-28-07

View solution in original post

martin_mueller
SplunkTrust
SplunkTrust

Take a look at this run-anywhere example:

| stats count | eval "Status for 2014-28-07" = "foo" | foreach "Status for 20*" [eval date = "20<<MATCHSTR>>"]

Result:

Status for 2014-28-07   date
foo                     2014-28-07

sc0tt
Builder

Brilliant! Just what I needed.

0 Karma

sc0tt
Builder

It is the column header. For example:
Id, Status for 2014-28-07
01, active
02, inactive

0 Karma

strive
Influencer

Is this column header OR a value in a column. If it is value in a column then what is the column header name.

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...