Splunk Search

How to rename fields in a table without changing column order?

bowesmana
SplunkTrust
SplunkTrust

Any suggestions on how to rename fields and keep those fields in their stated table order.

I have a bunch of fields that are attributes that are named is_XXX. I want all those fields to be on the right hand side of the table, so if I do

 

 

<search>
| foreach is_* [ eval "zz_<<MATCHSTR>>"=if(<<FIELD>>=1,"","")]
| fields - is_* 
| table entity entity_type *

 

 

it works nicely and puts the first two named fields as the first two columns, then other fields then all the zz_* fields. 

bowesmana_1-1673939567509.png

 

However, as soon as I add

 

 

| rename zz_* as *

 

 

it changes the order and sorts all the columns (apart from the first named two) into alphabetical order.

Any specifically named fields I add after entity_type persist the column order but all fields output as a result of the wildcard lose their order after the rename.

bowesmana_2-1673939659718.png

 

 

Labels (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

transpose, alter the values in the field names column, transpose back again

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

transpose, alter the values in the field names column, transpose back again

bowesmana
SplunkTrust
SplunkTrust

Yup, that worked - I've always wondered about the performance of a transpose with a large dataset. I imagine under the hood it could be pretty efficient. Probably need to do some performance comparisons with it to see if it's a practical solution for big sets.

Thanks!

 

0 Karma

bowesmana
SplunkTrust
SplunkTrust

@ITWhisperer 

FYI: transpose 0 with large row count won't work

| makeresults count=100
| eval x=1
| eval r=mvrange(1,10000,1)
| mvexpand r
| table r x
| transpose 0 column_name=header

without the transpose it creates the million rows quickly, but the transpose just dies - been running for a while now...

Anyway, the solution works for my use case.

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!

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

Customer success is front and center at .conf25

Hi Splunkers, If you are not able to be at .conf25 in person, you can still learn about all the latest news ...