Splunk Search
Highlighted

How do I translate standard IPv4 addresses into a format with leading zeroes in each octet in order for each octet to always contain 3 digits?

Explorer

I need to do this to perform lookups on a customer database where the IP addresses are stored in the format with leading zeroes.

Thank you!

Highlighted

Re: How do I translate standard IPv4 addresses into a format with leading zeroes in each octet in order for each octet to always contain 3 digits?

SplunkTrust
SplunkTrust

Try like this (run anywhere sample, replace first line with your actual search and update the field name). Two methods give, use any one.

| gentimes start=-1 | eval ip_addr="111.22.3.44 1.22.33.444 11.22.33.44" | table ip_addr | makemv ip_addr | mvexpand ip_addr 
| eval ip_addr_modified=replace(replace(ip_addr,"(\d+)\.(\d+)\.(\d+)\.(\d+)","00\1.00\2.00\3.00\4"),"0*(\d{3})\.0*(\d{3})\.0*(\d{3})\.0*(\d{3})","\1.\2.\3.\4")
| eval ip_addr_modified2=replace("00".replace(ip_addr,"\.",".00"),"0*(\d{3})\.0*(\d{3})\.0*(\d{3})\.0*(\d{3})","\1.\2.\3.\4")

View solution in original post

Highlighted

Re: How do I translate standard IPv4 addresses into a format with leading zeroes in each octet in order for each octet to always contain 3 digits?

Explorer

Works Great! Thank you very much!

0 Karma
Speak Up for Splunk Careers!

We want to better understand the impact Splunk experience and expertise has has on individuals' careers, and help highlight the growing demand for Splunk skills.