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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...