Splunk Search

How to remove text from host name in search results?

lbogle
Contributor

Hey Splunkers,
I have a search that is successfully returning search results as needed, however, I'd like to clean up the results a little.

The search returns the following:

HostName=PC-USERNAME.DOMAINNAME.COM

There are some databases that this search references that do not have the .DOMAINNAME.COM tacked onto the end of it and in the name of standardizing the search output, i'd like to clean it up so that they all look the same.
Is it possible to remove .DOMAINNAME.COM from the HostNames in the search results?

Thanks!

Tags (3)
1 Solution

somesoni2
Revered Legend

There are many options, see this runanywhere sample search

|gentimes start=-1 |eval HostName="PC-USERNAME.DOMAINNAME.COM PC-USERNAME" 
| makemv HostName|mvexpand HostName 
| eval HostName1=mvindex(split(HostName,"."),0) 
| eval HostName2=replace(HostName,"(.*)(\.\w+\.\w+)","\1") 
| eval HostName3=HostName | rex field=HostName3 mode=sed "s/(\.\w+\.\w+)$//g"

View solution in original post

somesoni2
Revered Legend

There are many options, see this runanywhere sample search

|gentimes start=-1 |eval HostName="PC-USERNAME.DOMAINNAME.COM PC-USERNAME" 
| makemv HostName|mvexpand HostName 
| eval HostName1=mvindex(split(HostName,"."),0) 
| eval HostName2=replace(HostName,"(.*)(\.\w+\.\w+)","\1") 
| eval HostName3=HostName | rex field=HostName3 mode=sed "s/(\.\w+\.\w+)$//g"

lbogle
Contributor

Just FYI, there are many PC-USERNAME.DOMAINNAME.COM in the results. Can a wild card be used to indicate anything before .DOMAINNAME.COM? And if so, what is the syntax?

0 Karma
Get Updates on the Splunk Community!

A Guide To Cloud Migration Success

As enterprises’ rapid expansion to the cloud continues, IT leaders are continuously looking for ways to focus ...

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...