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

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...

Design, Compete, Win: Submit Your Best Splunk Dashboards for a .conf26 Pass

Hello Splunkers,  We’re excited to kick off a Splunk Dashboard contest! We know that dashboards are a primary ...

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...