Splunk Search

Remove spaces in field values and run stats/timechart with new names

smhsplunk
Communicator

I notice Splunk uses the first Word when using stats, so I need to rename the fields to single words or connected words.

I am trying to remove spaces in field names and use the new name to be used in drop-downs and timecharts. Till now, I've been unable to perform this. Following is a drop-down menu where
I only want unique City Names. I would also want to use the new names in stats.

       source=location sourcetype=location_data
                  | search * "Current City" 
          | dedup "Current City"  
                  | sort "Current City"                   
          | rename "Current City" as City 
                  | rename "Current State" as State 
                  | rename "Current Location" as Location
                  | fields City
0 Karma
1 Solution

woodcock
Esteemed Legend

OK, so the problem is not that your field name has spaces but rather that your field value does. So you do not need rename, you need something else. Try using this (early in your command chain):

... | rex field="Current City" mode=sed "s/ /_/g"

View solution in original post

woodcock
Esteemed Legend

OK, so the problem is not that your field name has spaces but rather that your field value does. So you do not need rename, you need something else. Try using this (early in your command chain):

... | rex field="Current City" mode=sed "s/ /_/g"

smhsplunk
Communicator

Excellent this works, is it possible to do the same thing without removing spaces ? Keeping column values as it is ?

0 Karma

woodcock
Esteemed Legend

Yes, you can protect your values by surrounding the field name references with double-quotes or dollar-signs. It all depends on your actual XML and search.

0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...