<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to sort value in a multivalue field of IP address in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-value-in-a-multivalue-field-of-IP-address/m-p/671352#M230085</link>
    <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;Sorting values in a multi-value field of IP addresses involves arranging the IPs in a specific order. Here's a simple way to do it:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Separate IP Addresses:&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;If your multi-value field contains multiple IPs in a single string, separate them into individual values.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Convert IPs to Numeric Format:&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Convert each IP address to its numeric equivalent. You can do this by treating each part of the IP as a number and combining them.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Sort Numeric Values:&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Sort the numeric representations of the IPs in ascending or descending order, depending on your preference.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Convert Back to IP Format:&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Once sorted, convert the numeric values back to IP address format.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;STRONG&gt;Example:&lt;/STRONG&gt; Suppose you have IP addresses like "192.168.1.2," "10.0.0.1," and "172.16.0.5."&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Separate: ["192.168.1.2", "10.0.0.1", "172.16.0.5"]&lt;/LI&gt;&lt;LI&gt;Convert: [3232235778, 167772161, 2886729733]&lt;/LI&gt;&lt;LI&gt;Sort: [167772161, 2886729733, 3232235778]&lt;/LI&gt;&lt;LI&gt;Convert Back: ["10.0.0.1", "172.16.0.5", "192.168.1.2"]&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;You can use programming languages like Python or JavaScript for this task. Always consider the specific requirements of your project and the tools available for your development environment.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Sat, 09 Dec 2023 09:04:16 GMT</pubDate>
    <dc:creator>soniya-01</dc:creator>
    <dc:date>2023-12-09T09:04:16Z</dc:date>
    <item>
      <title>How to sort value in a multivalue field of IP address</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-value-in-a-multivalue-field-of-IP-address/m-p/671273#M230056</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know that&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;mvsort command sort values lexicographically.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mnj1809_0-1702049305752.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/28426i584412FAEA1E2C04/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mnj1809_0-1702049305752.png" alt="mnj1809_0-1702049305752.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;But I want the output as below:&lt;BR /&gt;&lt;BR /&gt;62.0.3.75&lt;BR /&gt;63.0.3.84&lt;BR /&gt;75.0.3.80&lt;BR /&gt;92.0.4.159&lt;BR /&gt;119.0.6.159&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 15:36:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-value-in-a-multivalue-field-of-IP-address/m-p/671273#M230056</guid>
      <dc:creator>mnj1809</dc:creator>
      <dc:date>2023-12-08T15:36:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort value in a multivalue field of IP address</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-value-in-a-multivalue-field-of-IP-address/m-p/671310#M230066</link>
      <description>&lt;P&gt;Using split in your emulation kind of obscures characteristics of the real data, how real data becomes multivalued, etc. &amp;nbsp;But working from this - please post test code/mock code in text, not screenshot, there is a potential way to leverage sort command that automatically recognizes IPv4 format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval ip = split("119.0.6.159,62.0.3.75,63.0.3.84,75.0.3.80,92.0.4.159", ",")
| mvexpand ip
| sort ip
| stats values(ip) as ip list(ip) as sorted_ip&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This gives you&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;ip&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;sorted_ip&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;119.0.6.159&lt;/DIV&gt;&lt;DIV class=""&gt;62.0.3.75&lt;/DIV&gt;&lt;DIV class=""&gt;63.0.3.84&lt;/DIV&gt;&lt;DIV class=""&gt;75.0.3.80&lt;/DIV&gt;&lt;DIV class=""&gt;92.0.4.159&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;62.0.3.75&lt;/DIV&gt;&lt;DIV class=""&gt;63.0.3.84&lt;/DIV&gt;&lt;DIV class=""&gt;75.0.3.80&lt;/DIV&gt;&lt;DIV class=""&gt;92.0.4.159&lt;/DIV&gt;&lt;DIV class=""&gt;119.0.6.159&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;mvexpand can be expensive. &amp;nbsp;list can be memory hungry. &amp;nbsp;So, think of data strategy if performance is a concern. &amp;nbsp;Do you have to present results in multivalue format?&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 19:52:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-value-in-a-multivalue-field-of-IP-address/m-p/671310#M230066</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-12-08T19:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort value in a multivalue field of IP address</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-value-in-a-multivalue-field-of-IP-address/m-p/671319#M230073</link>
      <description>&lt;P&gt;Thanks Yuanliu for your quick reply. Shared solution works for me. But now I am getting error&amp;nbsp;&lt;STRONG&gt;'list' command: Limit of '100' for values reached. Additional values may have been truncated or ignored. &lt;/STRONG&gt;Could you please suggest to resolve this issue without updating the limits.conf file?&lt;BR /&gt;&lt;BR /&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 22:05:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-value-in-a-multivalue-field-of-IP-address/m-p/671319#M230073</guid>
      <dc:creator>mnj1809</dc:creator>
      <dc:date>2023-12-08T22:05:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort value in a multivalue field of IP address</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-value-in-a-multivalue-field-of-IP-address/m-p/671327#M230075</link>
      <description>&lt;P&gt;If presenting result in multivalue format is that important, you can pad decimal octet IPv4 address to full three digits, then use mvsort.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval ip = split("119.0.6.159,62.0.3.75,63.0.3.84,75.0.3.80,92.0.4.159", ",")
``` data emulation above ```
| eval idx = mvrange(0,4)
| foreach ip mode=multivalue
    [eval sorted_ip = mvappend(sorted_ip, mvjoin(mvmap(idx, printf("%.3d", tonumber(mvindex(split(&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;, "."), idx)))), "."))]
| eval sorted_ip = mvsort(sorted_ip)
| table ip sorted_ip&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You'll get&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;ip&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;sorted_ip&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;119.0.6.159&lt;/DIV&gt;&lt;DIV class=""&gt;62.0.3.75&lt;/DIV&gt;&lt;DIV class=""&gt;63.0.3.84&lt;/DIV&gt;&lt;DIV class=""&gt;75.0.3.80&lt;/DIV&gt;&lt;DIV class=""&gt;92.0.4.159&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;062.000.003.075&lt;/DIV&gt;&lt;DIV class=""&gt;063.000.003.084&lt;/DIV&gt;&lt;DIV class=""&gt;075.000.003.080&lt;/DIV&gt;&lt;DIV class=""&gt;092.000.004.159&lt;/DIV&gt;&lt;DIV class=""&gt;119.000.006.159&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;If you want the decimal octets to be stripped of padding, you can do that with printf or any number of other methods. &amp;nbsp;I'll leave this for your homework.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 23:53:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-value-in-a-multivalue-field-of-IP-address/m-p/671327#M230075</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-12-08T23:53:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort value in a multivalue field of IP address</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-value-in-a-multivalue-field-of-IP-address/m-p/671352#M230085</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;Sorting values in a multi-value field of IP addresses involves arranging the IPs in a specific order. Here's a simple way to do it:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Separate IP Addresses:&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;If your multi-value field contains multiple IPs in a single string, separate them into individual values.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Convert IPs to Numeric Format:&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Convert each IP address to its numeric equivalent. You can do this by treating each part of the IP as a number and combining them.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Sort Numeric Values:&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Sort the numeric representations of the IPs in ascending or descending order, depending on your preference.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Convert Back to IP Format:&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Once sorted, convert the numeric values back to IP address format.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;STRONG&gt;Example:&lt;/STRONG&gt; Suppose you have IP addresses like "192.168.1.2," "10.0.0.1," and "172.16.0.5."&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Separate: ["192.168.1.2", "10.0.0.1", "172.16.0.5"]&lt;/LI&gt;&lt;LI&gt;Convert: [3232235778, 167772161, 2886729733]&lt;/LI&gt;&lt;LI&gt;Sort: [167772161, 2886729733, 3232235778]&lt;/LI&gt;&lt;LI&gt;Convert Back: ["10.0.0.1", "172.16.0.5", "192.168.1.2"]&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;You can use programming languages like Python or JavaScript for this task. Always consider the specific requirements of your project and the tools available for your development environment.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Sat, 09 Dec 2023 09:04:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-value-in-a-multivalue-field-of-IP-address/m-p/671352#M230085</guid>
      <dc:creator>soniya-01</dc:creator>
      <dc:date>2023-12-09T09:04:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort value in a multivalue field of IP address</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-value-in-a-multivalue-field-of-IP-address/m-p/671385#M230098</link>
      <description>&lt;P&gt;At the risk of spoiling&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/189754"&gt;@mnj1809&lt;/a&gt;'s homework, I would condense this to a single eval statement:&lt;/P&gt;&lt;PRE&gt;| eval ip=mvmap(mvsort(mvmap(ip, mvjoin(mvmap(split(ip, "."), substr("00".ip, -3)), "."))), mvjoin(mvmap(split(ip, "."), coalesce(nullif(ltrim(ip, "0"), ""), "0")), "."))&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;However, understanding nested mvmap magic is also homework.&lt;/P&gt;</description>
      <pubDate>Sun, 10 Dec 2023 20:56:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-value-in-a-multivalue-field-of-IP-address/m-p/671385#M230098</guid>
      <dc:creator>tscroggins</dc:creator>
      <dc:date>2023-12-10T20:56:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort value in a multivalue field of IP address</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-value-in-a-multivalue-field-of-IP-address/m-p/671430#M230103</link>
      <description>&lt;P&gt;Thank you so much&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/49493"&gt;@tscroggins&lt;/a&gt;. This helped me.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Dec 2023 10:46:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-value-in-a-multivalue-field-of-IP-address/m-p/671430#M230103</guid>
      <dc:creator>mnj1809</dc:creator>
      <dc:date>2023-12-11T10:46:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort value in a multivalue field of IP address</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-value-in-a-multivalue-field-of-IP-address/m-p/672065#M230260</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/49493"&gt;@tscroggins&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;Yes it's really complex to understand below SPL code due to nested commands. could you please brief how is the below code is working?&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| makeresults
| eval ip = split("119.0.6.159,62.0.3.75,63.0.3.84,75.0.3.80,92.0.4.159", ",")
| eval idx = mvrange(0,4)
| foreach ip mode=multivalue
[eval sorted_ip = mvappend(sorted_ip, mvjoin(mvmap(idx, printf("%.3d", tonumber(mvindex(split(&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;, "."), idx)))), "."))]
| eval sorted_ip=mvmap(mvsort(mvmap(sorted_ip, mvjoin(mvmap(split(sorted_ip, "."), substr("00".sorted_ip, -3)), "."))), mvjoin(mvmap(split(sorted_ip, "."), coalesce(nullif(ltrim(sorted_ip, "0"), ""), "0")), "."))&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Dec 2023 09:05:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-value-in-a-multivalue-field-of-IP-address/m-p/672065#M230260</guid>
      <dc:creator>mnj1809</dc:creator>
      <dc:date>2023-12-16T09:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort value in a multivalue field of IP address</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-value-in-a-multivalue-field-of-IP-address/m-p/672068#M230261</link>
      <description>&lt;P&gt;That's a fair question. &amp;nbsp;So, first let me break the search to a less nested form, then describe the intentions/semantics. (As always, consult syntax and usage in &lt;A href="https://docs.splunk.com/Documentation/Splunk/9.1.2/SearchReference/" target="_blank" rel="noopener"&gt;Search Reference&lt;/A&gt;.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval ip = split("119.0.6.159,62.0.3.75,63.0.3.84,75.0.3.80,92.0.4.159", ",")
``` data emulation above ```
| eval idx = mvrange(0,4)
| foreach ip mode=multivalue
[| eval interim1 = split(&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;, "."),
  interim2 = mvmap(idx, printf("%.3d", tonumber(mvindex(interim1, idx)))),
  interim3 = mvjoin(interim2, "."),
  sorted_ip_padded = mvappend(sorted_ip_padded, interim3)]
| eval sorted_ip_padded = mvsort(sorted_ip_padded)
| foreach sorted_ip_padded mode=multivalue
[| eval interim4 = split(&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;, "."),
  interim5 = mvmap(idx, printf("%d", tonumber(mvindex(interim4, idx)))),
  interim6 = mvjoin(interim5, "."),
  sorted_ip = mvappend(sorted_ip, interim6)]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(I'm using a different approach to fill your homework from &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/49493"&gt;@tscroggins&lt;/a&gt;'s proposal because foreach is easier to break down. &amp;nbsp;I also use a more symmetric approach so it can be explained more readily.)&lt;/P&gt;&lt;P&gt;Here is a key card behind the formula:&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="17.17171717171717%" height="25px"&gt;split&lt;/TD&gt;&lt;TD width="82.82828282828284%" height="25px"&gt;An IPv4 address will result will contain a 4-element array, &lt;EM&gt;indexed&lt;/EM&gt; from 0 to 3.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="17.17171717171717%" height="25px"&gt;mvrange&lt;/TD&gt;&lt;TD width="82.82828282828284%" height="25px"&gt;Generate a 4-element array with &lt;EM&gt;values&lt;/EM&gt; from 0 to 3.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="17.17171717171717%" height="47px"&gt;mvsort&lt;/TD&gt;&lt;TD width="82.82828282828284%" height="47px"&gt;This is lexicographic sort of array elements. &amp;nbsp;For 0-padded IPv4 addresses, it is equivalent to numeric sort that you desired.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="17.17171717171717%" height="25px"&gt;printf&lt;/TD&gt;&lt;TD width="82.82828282828284%" height="25px"&gt;Pad and unpad&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;To examine the formula, first take a look at output below:&lt;/P&gt;&lt;TABLE width="791px"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;idx&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;interim1&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;interim2&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;interim3&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;interim4&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;interim5&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;interim6&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;ip&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;sorted_ip&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;sorted_ip_padded&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="40px"&gt;&lt;DIV class=""&gt;0&lt;/DIV&gt;&lt;DIV class=""&gt;1&lt;/DIV&gt;&lt;DIV class=""&gt;2&lt;/DIV&gt;&lt;DIV class=""&gt;3&lt;/DIV&gt;&lt;/TD&gt;&lt;TD width="46.671875px"&gt;&lt;DIV class=""&gt;92&lt;/DIV&gt;&lt;DIV class=""&gt;0&lt;/DIV&gt;&lt;DIV class=""&gt;4&lt;/DIV&gt;&lt;DIV class=""&gt;159&lt;/DIV&gt;&lt;/TD&gt;&lt;TD width="46.671875px"&gt;&lt;DIV class=""&gt;092&lt;/DIV&gt;&lt;DIV class=""&gt;000&lt;/DIV&gt;&lt;DIV class=""&gt;004&lt;/DIV&gt;&lt;DIV class=""&gt;159&lt;/DIV&gt;&lt;/TD&gt;&lt;TD width="135.984375px"&gt;092.000.004.159&lt;/TD&gt;&lt;TD width="46.671875px"&gt;&lt;DIV class=""&gt;119&lt;/DIV&gt;&lt;DIV class=""&gt;000&lt;/DIV&gt;&lt;DIV class=""&gt;006&lt;/DIV&gt;&lt;DIV class=""&gt;159&lt;/DIV&gt;&lt;/TD&gt;&lt;TD width="46.671875px"&gt;&lt;DIV class=""&gt;119&lt;/DIV&gt;&lt;DIV class=""&gt;0&lt;/DIV&gt;&lt;DIV class=""&gt;6&lt;/DIV&gt;&lt;DIV class=""&gt;159&lt;/DIV&gt;&lt;/TD&gt;&lt;TD width="97.125px"&gt;119.0.6.159&lt;/TD&gt;&lt;TD width="97.125px"&gt;&lt;DIV class=""&gt;119.0.6.159&lt;/DIV&gt;&lt;DIV class=""&gt;62.0.3.75&lt;/DIV&gt;&lt;DIV class=""&gt;63.0.3.84&lt;/DIV&gt;&lt;DIV class=""&gt;75.0.3.80&lt;/DIV&gt;&lt;DIV class=""&gt;92.0.4.159&lt;/DIV&gt;&lt;/TD&gt;&lt;TD width="97.125px"&gt;&lt;DIV class=""&gt;62.0.3.75&lt;/DIV&gt;&lt;DIV class=""&gt;63.0.3.84&lt;/DIV&gt;&lt;DIV class=""&gt;75.0.3.80&lt;/DIV&gt;&lt;DIV class=""&gt;92.0.4.159&lt;/DIV&gt;&lt;DIV class=""&gt;119.0.6.159&lt;/DIV&gt;&lt;/TD&gt;&lt;TD width="135.984375px"&gt;&lt;DIV class=""&gt;062.000.003.075&lt;/DIV&gt;&lt;DIV class=""&gt;063.000.003.084&lt;/DIV&gt;&lt;DIV class=""&gt;075.000.003.080&lt;/DIV&gt;&lt;DIV class=""&gt;092.000.004.159&lt;/DIV&gt;&lt;DIV class=""&gt;119.000.006.159&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Inside the foreach loop, the following steps are followed:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Breakdown IPv4 into octets. (interim1, interim4)&lt;/LI&gt;&lt;LI&gt;Pad/unpad each octet. (interim2, interim5)&lt;/LI&gt;&lt;LI&gt;Reassemble IPv4 with/without padding. (interim3, interim6)&lt;/LI&gt;&lt;LI&gt;Assemble padded/unpadded IPv4 into array. (sorted_ip_padded, sorted_ip)&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Now, the only nested element is padding/unpadding: mvmap(idx, printf("%.3d", tonumber(mvindex(interim1, idx))))/mvmap(idx, printf("%d", tonumber(mvindex(interim4, idx)))). &amp;nbsp;Because of the way tonumber works in SPL, it cannot be broken down further. &amp;nbsp;But the principle is not too complicated. &amp;nbsp;&lt;FONT face="courier new,courier"&gt;idx&lt;/FONT&gt;&amp;nbsp;is the index of octet. &amp;nbsp;So, it is an iteration of printf("%d", octet) over each octet, where octet = mvindex(interim4, idx) wrapped in tonumber().&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2023 19:07:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-value-in-a-multivalue-field-of-IP-address/m-p/672068#M230261</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-12-15T19:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort value in a multivalue field of IP address</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-value-in-a-multivalue-field-of-IP-address/m-p/672390#M230315</link>
      <description>&lt;P&gt;Thanks for the explanation&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2023 11:17:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-value-in-a-multivalue-field-of-IP-address/m-p/672390#M230315</guid>
      <dc:creator>mnj1809</dc:creator>
      <dc:date>2023-12-20T11:17:40Z</dc:date>
    </item>
  </channel>
</rss>

