Splunk Search

How to rename Splunk column names?

nibinabr
Communicator

Hi,

I have a query that evaluates the value of a variable like this

*...|eval var1= var2*10|....*

where var1 and var2 are variables.

Now I need to rename the column header by doing something like this

*rename column_name as "Number ".var1." is good"* .

But the output I see is *"Number ".var1." is good"* and var1 is not getting replaced by the value. What is the right way of doing this ?

Any help will be appreciated.

Labels (1)
Tags (2)
0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

rename can't access column values. Try this:

... | eval Number {var1} is good = column_name | fields - column_name

View solution in original post

martin_mueller
SplunkTrust
SplunkTrust

rename can't access column values. Try this:

... | eval Number {var1} is good = column_name | fields - column_name

sukansingh
Explorer

what if variable is holding the column_name and then I want to sort that column.

 for example

my_search | eval date="2023-02-02" | sort  - $date

is it possible to sort by column name which is dynamically generated So i won't know the exact name But variable holds the column name So I can just use sort - $Variable?

0 Karma

bowesmana
SplunkTrust
SplunkTrust

Please post this as a new question rather than asking a different variant of another question on an 8 year old answer question. It will get more attention.

0 Karma

nibinabr
Communicator

I really appreciate you sharing this example. It is bit confusing that it doesn't work for me when I have the value of var1 being calculated just after my query. When I moved this calculation just before the eval Number {var1} is good = column_name | fields - column_name, it worked for me.

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Well, it can't use values from the future...

0 Karma

nibinabr
Communicator

I mean
stats.....|eval var1=var2*10|....|....|......|....|eval Number {var1} is good = column_name | fields - column_name
didnot work for me.

It worked when I changed the above to
stats.....|....|....|......|....|eval var1=var2*10|eval Number {var1} is good = column_name | fields - column_name

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Try running this dummy example:

| stats count | eval var1="42 43 44" | makemv var1 | mvexpand var1 | eval column_name = "foo" | eval Number {var1} is good = column_name | fields - column_name

alt text

0 Karma

nibinabr
Communicator

Thanks @martin_muller for the quick reply. I tried your solution and now the column in the output now changed to "Number is good". It is not printing the value of var1 between "Number" and "is".

0 Karma
Get Updates on the Splunk Community!

Splunk Decoded: Service Maps vs Service Analyzer Tree View vs Flow Maps

It’s Monday morning, and your phone is buzzing with alert escalations – your customer-facing portal is running ...

What’s New in Splunk Observability – September 2025

What's NewWe are excited to announce the latest enhancements to Splunk Observability, designed to help ITOps ...

Fun with Regular Expression - multiples of nine

Fun with Regular Expression - multiples of nineThis challenge was first posted on Slack #regex channel ...