Splunk Search

transpose on selected fields

Susha
Engager

Hi Team,

I want to transpose few fields as below ..

(index=abc OR index=def) category= * OR NOT blocked =0 AND NOT blocked =2
|rex field=index "(?<Local_Market>[^cita]\w.*?)_"
| stats count(Local_Market) as Blocked by Local_Market
| addcoltotals col=t labelfield=Local_Market label="Total"
| append [search (index=abc OR index=def) blocked =0 | rex field=index "(?<Local_Market>\w.*?)_"
| stats count as Detected by Local_Market
| addcoltotals col=t labelfield=Local_Market label="Total"]
| stats values(*) as * by Local_Market
| transpose 0 header_field=Local_Market column_name=Local_Market

here i want to add one column of date ( eval Time=strftime(_time,"%m/%d/%y")) which should not be transpose ..

date                    Local_Market    Total   a  b   c
05-09-2021       INDIA                     3      1  1  1
05-09-2021       UK                          5       3  2  0

Tags (1)
0 Karma

PickleRick
SplunkTrust
SplunkTrust

I don't follow. You want to have the date column left alone and all other columns transposed? It can't work even from simply algebraic point of view - you have two rows but three columns you want to transpose to rows.

Or is the table you presented the desired format?

Either way, I'd just add "static" column or row and transpose it if needed.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

_time does not exist due to the stats commands removing it from the event pipeline. Which value of time do you want to use? now() or earliest/latest from the search timeframe or something else?

0 Karma

Susha
Engager

@ITWhisperer  this report is scheduled for yesterday so i want to give yesterday date only .. like only 09-06-2021

Tags (1)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| addinfo
| eval date=info_min_time
| fieldformat date=strftime(date,"%m-%d-%Y")
| fields - info_*
0 Karma

Susha
Engager

thanks a lot @ITWhisperer  its working perfectly .. just one more thing .. as of now date column is coming at last column .. how can we place it in first column ..

 

 

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!

Get Agentic with Splunk Lantern: Connect to Cisco Cloud Control, Transform ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...

July Community Events: Master ITSI 5.0 & Automate Splunk

Struggling with alert fatigue or feeling like you're spending more time on infrastructure maintenance than ...

New Release of Federated Search: Bringing Splunk Analytics to More of Your Data

Organizations today are generating more data than ever and storing it across cloud object stores, data lakes, ...