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

What Is Splunk? Here’s What You Can Do with Splunk

Hey Splunk Community, we know you know Splunk. You likely leverage its unparalleled ability to ingest, index, ...

Level Up Your .conf25: Splunk Arcade Comes to Boston

With .conf25 right around the corner in Boston, there’s a lot to look forward to — inspiring keynotes, ...

Manual Instrumentation with Splunk Observability Cloud: How to Instrument Frontend ...

Although it might seem daunting, as we’ve seen in this series, manual instrumentation can be straightforward ...