Splunk Search

Formatting output in table

krusovice
Path Finder

Hi all,

I've a request to come out with a table with information as below.

My query so far is to extract the required data from the log:

index=*  | search "$clicked_request$ - Country: $clicked_country$ - City: $City$ - Total: $total$"

Correct match with log data:

2018-02-21 01:50:22.600 INFO Request_A - Country: UK - City: LDN - Total: 120
2018-02-21 01:57:22.300 INFO Request_A - Country: UK - City: LDN - Total: 130
2018-02-21 02:00:22.390 INFO Request_A - Country: UK - City: MAN - Total: 100

However, I have the problem to format it into desired table format as below:

DATE         COUNTRY        CITY       DATE_HOUR          TOTAL
2018-02-21  UK          LDN              1         120
                                                1          130
                            MAN              2         100

How can I do this with the query?

Thanks in advance.

Tags (1)
0 Karma
1 Solution

deepashri_123
Motivator

Hey krusovoice,
Try something like this,
index=* | eval date=strftime(_time, "%Y-%m-%d") | stats values(total) AS total values(date_hour) AS date_hour by date,country,city

Let me know if this works!!
I am assuming that your fields are already extracted

View solution in original post

0 Karma

deepashri_123
Motivator

Hey krusovoice,
Try something like this,
index=* | eval date=strftime(_time, "%Y-%m-%d") | stats values(total) AS total values(date_hour) AS date_hour by date,country,city

Let me know if this works!!
I am assuming that your fields are already extracted

0 Karma

krusovice
Path Finder

hi @deepashri_123,

You've given me some idea how to construct the stats command. I've added with eval prior to stats to extract the value of $$.

Would you mind to reply as answer to my post so that I've click "accept as answer"?

Thank you very much for your help.

0 Karma

krusovice
Path Finder

sorry, $$ should be :

$<token_name>$
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...