Splunk Search

renaming fields in search

asarolkar
Builder

I have a query like this

sourcetype="beta" index="alpha" | table fieldA, fieldB, fieldC

how do I rename fields fieldA to A, fieldB to B and fieldC to C

These fields are strings AND numbers (not sure how I would use stats or table)

1 Solution

sdaniels
Splunk Employee
Splunk Employee

you can use the rename command .... | rename fieldA AS newname, fieldB AS b | table newname, b

View solution in original post

landen99
Motivator

Perhaps more elegant (and practical for many fields) to do:

| rename field* AS *

jbuckner85
Path Finder

Thank you, this is very useful!

asarran
Path Finder

Hey, fellow Splunkers,

When I actually attempted to conduct multiple rename fields using that method, I receive the following error: rename [old_name AS/TO/-> new_name]+

0 Karma

cam343
Path Finder

Can you post the search it should be like:

| rename user_name AS user, src AS "IP Address", host AS "Server Name"

hope that helps...

0 Karma

sdaniels
Splunk Employee
Splunk Employee

you can use the rename command .... | rename fieldA AS newname, fieldB AS b | table newname, b

sdaniels
Splunk Employee
Splunk Employee

Agreed, I just changed it.

0 Karma

cam343
Path Finder

While the above works, you are probably better expanding rename command instead of piping to rename for every field you want renamed.

eg. | rename fieldA AS newnameA, fieldB AS newnameB, fieldC AS newnameC

instead of:
| rename fieldA AS newnameA |rename fieldB AS newnameB |rename fieldC AS newnameC

asarolkar
Builder

yup.. thanks a bunch

0 Karma
Get Updates on the Splunk Community!

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...

Combine Multiline Logs into a Single Event with SOCK: a Step-by-Step Guide for ...

Combine multiline logs into a single event with SOCK - a step-by-step guide for newbies Olga Malita The ...