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!

Get the T-shirt to Prove You Survived Splunk University Bootcamp

As if Splunk University, in Las Vegas, in-person, with three days of bootcamps and labs weren’t enough, now ...

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Wondering How to Build Resiliency in the Cloud?

IT leaders are choosing Splunk Cloud as an ideal cloud transformation platform to drive business resilience,  ...