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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...