Splunk Search

Combine a numerical field with a string field separated with a dash

subhrangshu
Explorer

Hello,

I am trying to combine couple of fields data separated by a dash. Tried few options but could not get the expected output.

My query is:

index=test sourcetype="test-abc"  ("enter start()")
| rename job_id as JOB_ID
| stats earliest(_time) AS Earliest by JOB_ID
| eval FirstEvent=strftime(Earliest,"%b %d, %Y %H:%M:%S")
| eval JOB_ID_STR=tostring(JOB_ID)
| eval JOB-ID-WITH-TIME=printf("%s%z", JOB_ID_STR,FirstEvent)

In the above query: JOB_ID is a numerical data of length 4 digit. FirstEvent is string of time format of that event.

Ex:

JOB_ID = 9000 and FirstEvent = Jul 07, 2020 04:56:43

Using the above query and with printf function,  JOB-ID-WITH-TIME is returned as 9000Jul 07, 2020 04:56:43. 

I want the output to be like 9000-Jul 07, 2020 04:56:43 (a dash between JOB_ID and FirstEvent).

How to do it?

Thanks in advance for your time!

Labels (1)
0 Karma
1 Solution

diogofgm
SplunkTrust
SplunkTrust

You can just use eval for that:

JOB_ID = 9000 and FirstEvent = Jul 07, 2020 04:56:43

| eval job_with_time = JOB_ID + "-" + FirstEvent

------------
Hope I was able to help you. If so, some karma would be appreciated.

View solution in original post

Tags (1)

diogofgm
SplunkTrust
SplunkTrust

You can just use eval for that:

JOB_ID = 9000 and FirstEvent = Jul 07, 2020 04:56:43

| eval job_with_time = JOB_ID + "-" + FirstEvent

------------
Hope I was able to help you. If so, some karma would be appreciated.
Tags (1)

subhrangshu
Explorer

Thanks for the prompt reply. I don't know, how I missed this. Thanks again 😃

0 Karma
Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...