Splunk Search

Can a lookup be used for renaming a field name?

simpkins1958
Contributor

Trying to figure out if can rename field names using lookup and CSV file. Something like this:

index=main d_name="*" | dedup d_name | table _time d_name plat d_man d_mod user | rename d_name TO value from csv lookup

csv file:
fieldname,tableheader
d_name, Device Name
plat, Platform
d_man, Manufacturer
d_mod, Model
user, User

0 Karma

woodcock
Esteemed Legend

Like this:

... | rename [|inputcsv renameFields.csv| format "" "" "" "" "" "" | rex field=search mode=sed "s/ tableheader=/ AS /g s/fieldname=//g"]
0 Karma

ahansson89
Engager

I downvoted this post because does not work

0 Karma

aaraneta_splunk
Splunk Employee
Splunk Employee

@ahansson89 - Downvoting should only be reserved for suggestions/solutions that could be potentially harmful for a Splunk environment or goes completely against known best practices. Simply commenting with more information about what didn't work and what you've tried (or whatever other info may be relevant) would suffice to help you troubleshoot further.

0 Karma

sundareshr
Legend

Try this

index=main d_name="*" | dedup d_name |  table _time d_name plat d_man d_mod user | join d_name  [| inputlookup lookup.csv | rename fieldname AS d_name | ] | eval {tableheader}=d_name
0 Karma

simpkins1958
Contributor

Using rename command below is not working...

rename d_name as [| inputlookup fieldnames where fieldname="d_name" | return $tableheader]

0 Karma

diogofgm
SplunkTrust
SplunkTrust

Any reason to not just simply use FIELDALIAS in the props.conf of you sourcetype?

------------
Hope I was able to help you. If so, some karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...