Splunk Search

How to generate a table where the values of my "serviceType" field appear as a column headers?

kaushik1218
New Member

Below is the example of single request with multiple lines where ServiceType is different.

alt text

Required result to be as below, where Service type is placed into single row with different field names

alt text

Happy to take any other suggestions. Thanks in advance

0 Karma
1 Solution

somesoni2
Revered Legend

Well in your sample output, the field name is same and will not work. If output like below is acceptable, try the query.

OUTPUT

_time, RequestID SiteID Address senderURI serviceType StatusCode
xxx    yyy       xxx    ppp     qqqq      AnalogueTelevision,Broadband,..othervalues.. statuscodevalue

Query

..your current search | stats values(serviceType) as serviceType by   _time, RequestID SiteID Address senderURI StatusCode | nomv serviceType

OR
OUTPUT

_time, RequestID SiteID Address senderURI AnalogueTelevision Broadband DigitalTelevision Telephony StatusCode
xxx    yyy       xxx    ppp     qqqq      yes                yes       yes               yes   statuscodevalue

Query

..your current search | eval temp=_time."#".RequestID."#".SiteID."##".Address."#".senderURI."#".StatusCode | stats count over temp by serviceType | rex field=temp "(?<time>\d+)#(?<RequestID>[^#]+)#(?<SiteID>[^#]+)#(?<Address>[^#]+)#(?<senderURI>[^#]+)#(?<StatusCode>[^#]+)" | fields - temp | rename time as _time| table _time, RequestID SiteID Address senderURI * StatusCode

View solution in original post

0 Karma

somesoni2
Revered Legend

Well in your sample output, the field name is same and will not work. If output like below is acceptable, try the query.

OUTPUT

_time, RequestID SiteID Address senderURI serviceType StatusCode
xxx    yyy       xxx    ppp     qqqq      AnalogueTelevision,Broadband,..othervalues.. statuscodevalue

Query

..your current search | stats values(serviceType) as serviceType by   _time, RequestID SiteID Address senderURI StatusCode | nomv serviceType

OR
OUTPUT

_time, RequestID SiteID Address senderURI AnalogueTelevision Broadband DigitalTelevision Telephony StatusCode
xxx    yyy       xxx    ppp     qqqq      yes                yes       yes               yes   statuscodevalue

Query

..your current search | eval temp=_time."#".RequestID."#".SiteID."##".Address."#".senderURI."#".StatusCode | stats count over temp by serviceType | rex field=temp "(?<time>\d+)#(?<RequestID>[^#]+)#(?<SiteID>[^#]+)#(?<Address>[^#]+)#(?<senderURI>[^#]+)#(?<StatusCode>[^#]+)" | fields - temp | rename time as _time| table _time, RequestID SiteID Address senderURI * StatusCode
0 Karma

kaushik1218
New Member

thanks for your fast reply.

Apologies for not mentioning before, what will be the query if new field name of "serviceType" is to be displayed for every serviceType value. Something like below.

servicetype1 servicetype2 servicetype3 servicetype4
xxx yyy zzz www

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 ...