Splunk Search

Please help with Date extraction from below string

bhaskar5428
Explorer

i have system column "_time" with below output 

2022-03-16 11:12:18.723

i would like segregate date and time by rex command 

output should be like this with new column name 

Date = 2022-03-16

Time = 11:12:18

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

If it is already in the _time field, it is probably already in epoch time format, so try this

| eval Date=strftime(_time,"%F")
| eval Time=strftime(_time,"%T")

View solution in original post

0 Karma

bhaskar5428
Explorer

index=app_events_fx4cash_uk_prod source=*STPManager-servicemanagement.20220316-111218.log*
| rex field=_time "^(?<date>\d\d\d\d-\d\d-\d\d)\s+(?<time>\d\d:\d\d:\d\d\.\d\d\d"
| table date,time

am using this but getting error 

Error in 'rex' command: Encountered the following error while compiling the regex '^(?<date>\d\d\d\d-\d\d-\d\d)\s+(?<time>\d\d:\d\d:\d\d\.\d\d\d': Regex: missing closing parenthesis.
The search job has failed due to an error. You may be able view the job in the 
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @bhaskar5428,

sorry I missed a paranthesi at the end of the regex, please try this:

| rex field=_time "^(?<date>\d\d\d\d-\d\d-\d\d)\s+(?<time>\d\d:\d\d:\d\d\.\d\d\d)"

Ciao.

Giuseppe

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

If it is already in the _time field, it is probably already in epoch time format, so try this

| eval Date=strftime(_time,"%F")
| eval Time=strftime(_time,"%T")
0 Karma

bhaskar5428
Explorer

Thanks , it worked 

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @bhaskar5428,

let me understand: are you spoeaking of search time extraction or timestamp configuration?

if search time extraction, you could use a regex like this:

| rex "^(?<date>\d\d\d\d-\d\d-\d\d)\s+(?<time>\d\d:\d\d:\d\d\.\d\d\d"

Ciao.

Giuseppe

0 Karma
Get Updates on the Splunk Community!

Automatic Discovery Part 1: What is Automatic Discovery in Splunk Observability Cloud ...

If you’ve ever deployed a new database cluster, spun up a caching layer, or added a load balancer, you know it ...

Real-Time Fraud Detection: How Splunk Dashboards Protect Financial Institutions

Financial fraud isn't slowing down. If anything, it's getting more sophisticated. Account takeovers, credit ...

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

 Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...