Splunk Search

How to combine two different time source fields into _time

kaungset
New Member

Dears;

how can I combine Date/Time of two different source as follow;

CSV-01(pic-1) and CSV-02(pic-2) input in splunk
Query from splunk search and output as Splunk Query Output (pic-3)

pls kindly help the way;

alt text

Tags (2)
0 Karma
1 Solution

to4kawa
Ultra Champion

UPDATED:

index="CSV-01" OR index="CSV-02"
| eval Date=coalesce(Date, mvindex(split('Start Time'," "),0))
| eval Date=strptime(Date,"%d/%m/%Y")
| fieldformat Date=strftime(Date,"%d/%m/%Y")
| table Date City "Traffic(GB)" 
| rename "Traffic(GB)" as Traffic
| sort Traffic

Previous Answer:

| inputlookup csv_01
| append [ | inputlookup csv_02
| eval Date = mvindex(split('Start Time'," "),0)
| table Date City "Traffic(GB)" ]
| eval _time = strptime(Date,"%d/%m/%Y")
| rename "Traffic(GB)" as Traffic
| table _time City Traffic

Hi, @kaungset
How about this?

P.S. It is better not to use a field name with spaces (ex. Start Time)in CSV.
if my query doesn't work, maybe field name problem occurs.

View solution in original post

0 Karma

to4kawa
Ultra Champion

UPDATED:

index="CSV-01" OR index="CSV-02"
| eval Date=coalesce(Date, mvindex(split('Start Time'," "),0))
| eval Date=strptime(Date,"%d/%m/%Y")
| fieldformat Date=strftime(Date,"%d/%m/%Y")
| table Date City "Traffic(GB)" 
| rename "Traffic(GB)" as Traffic
| sort Traffic

Previous Answer:

| inputlookup csv_01
| append [ | inputlookup csv_02
| eval Date = mvindex(split('Start Time'," "),0)
| table Date City "Traffic(GB)" ]
| eval _time = strptime(Date,"%d/%m/%Y")
| rename "Traffic(GB)" as Traffic
| table _time City Traffic

Hi, @kaungset
How about this?

P.S. It is better not to use a field name with spaces (ex. Start Time)in CSV.
if my query doesn't work, maybe field name problem occurs.

0 Karma

kaungset
New Member

hi @to4kawa
Thank You!

when i try first SPL command line

1.| eval Date=coalesce(Date, mvindex(split('Start Time'," "),0)) was work

but 2nd & 3rd doesn't work well.

I try like this first line;
1. index="main"
| eval d=coalesce(Date,mvindex(split('Start Time'," "),0))
| starts count by d

but when I put 2nd & 3rd line it's show us No results found;
1. index="main"
| eval d=coalesce(Date,mvindex(split('Start Time'," "),0))
| eval Date=strptime(d,"%d/%m/%Y")
| fieldformat Date=strftime(Date,"%d/%m/%Y")
| starts count by Date

0 Karma

to4kawa
Ultra Champion

before stats, if Date is, the problem is stats.
if Date isn't, the problem is strptime.
but, I think no need strptime

0 Karma

kaungset
New Member

Hi,
Thank You for your reply!

Both source CSV format file 01 & 02 was already input to splunk and indexed.
It was indexed as 3 time values as follow;

_time(only system default), Date(1/30/2020), Start Time(1/30/2020 12:00:00 AM)

I want to combine values of Date & Start Time as only Date field


Date City Traffic
1/30/2020 A 102039

0 Karma

to4kawa
Ultra Champion

@kaungset
I see. my answer is updated. please confirm.

0 Karma

jarizeloyola
Path Finder

index = blah sourcetype = blah source IN ("*CSV-01","*CSV-02") |stats count by _time City "Traffic(GB)"|rename "Traffic(GB)" as Traffic| fields - count

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Build resilience for the agentic era: Join us at Splunk Go San Jose

AI is changing how organizations build, operate, and secure digital services. As teams adopt AI agents and ...

Manage Edge Processor pipelines end to end with APIs

This guide uses the Data Management APIs to create an Edge Processor, onboard one instance, deploy a pipeline ...

Splunk Brings Proof of Control to Digital Asset Transfers

Digital assets now sit inside the core of financial services. HSBC launched its Tokenized Deposit Service in ...