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!

Splunk Mobile: Your Brand-New Home Screen

Meet Your New Mobile Hub  Hello Splunk Community!  Staying connected to your data—no matter where you are—is ...

Introducing Value Insights (Beta): Understand the Business Impact your organization ...

Real progress on your strategic priorities starts with knowing the business outcomes your teams are delivering ...

Enterprise Security (ES) Essentials 8.3 is Now GA — Smarter Detections, Faster ...

As of today, Enterprise Security (ES) Essentials 8.3 is now generally available, helping SOC teams simplify ...