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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Event Series: The Agentic SOC: Trust Before Autonomy

AI is fundamentally changing security operations, but true progress requires more than just automation—it ...

Free Professional Services for .conf26 Attendees

This year at .conf26, we are doing something a little different. We are bringing the best minds from ...

Defend at Machine Speed: Your Guide to Security Sessions at .conf26

Splunk .conf26   With threats moving at machine speed and attack surfaces expanding across hybrid ...