Splunk Search

How to Split hostname, IP and exclude IP from result

Akmal57
Path Finder

Hi, i want to list out all the hostname in my tipwire log.

but my hostname field are as below:

Hostname

10.10.10.10 : Host A

192.0.0.0 : Host B

My hostname and ip are mixed and in the same field.

How do i split the hostname, IP and list out all the hostname only.

Please assist me on this. Thank you

Labels (4)
Tags (1)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

If you want both fields you can either use rex to get both fields or split to split the string on the : character and then assign the first split to ip and the second to host.

| rex field=Hostname "(?<ip>[^:]*):(?<host>.*)"
OR
| eval tmp=split(Hostname, ":")
| eval ip=mvindex(tmp, 0), host=mvindex(tmp, 1)
| fields - tmp

rex is neater and you can make this an automatically extracted field, so you don't have to do it as part of the search.

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

Use rex

| rex field=Hostname ".*:(?<host>.*)"

 which will give you a new field called host with everything from the : to the end

Akmal57
Path Finder

Hi @bowesmana , thank you for your response.

Your regex works great.

if i want the ip on another field, do i need to use another regex?

0 Karma

bowesmana
SplunkTrust
SplunkTrust

If you want both fields you can either use rex to get both fields or split to split the string on the : character and then assign the first split to ip and the second to host.

| rex field=Hostname "(?<ip>[^:]*):(?<host>.*)"
OR
| eval tmp=split(Hostname, ":")
| eval ip=mvindex(tmp, 0), host=mvindex(tmp, 1)
| fields - tmp

rex is neater and you can make this an automatically extracted field, so you don't have to do it as part of the search.

Akmal57
Path Finder

Owh ok, both working great as expected.

Thank you for your assist on this.

0 Karma
Get Updates on the Splunk Community!

.conf24 | Day 0

Hello Splunk Community! My name is Chris, and I'm based in Canberra, Australia's capital, and I travelled for ...

Enhance Security Visibility with Splunk Enterprise Security 7.1 through Threat ...

(view in My Videos)Struggling with alert fatigue, lack of context, and prioritization around security ...

Troubleshooting the OpenTelemetry Collector

  In this tech talk, you’ll learn how to troubleshoot the OpenTelemetry collector - from checking the ...