<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
> <channel><title>Comments on: Linux / UNIX Shell: Sort IP Address</title> <atom:link href="http://www.cyberciti.biz/faq/unix-linux-shell-script-sorting-ip-addresses/feed/" rel="self" type="application/rss+xml" /><link>http://www.cyberciti.biz/faq/unix-linux-shell-script-sorting-ip-addresses/</link> <description>Every answer asks a more beautiful question.</description> <lastBuildDate>Fri, 10 Feb 2012 19:55:56 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>By: tc</title><link>http://www.cyberciti.biz/faq/unix-linux-shell-script-sorting-ip-addresses/#comment-59989</link> <dc:creator>tc</dc:creator> <pubDate>Tue, 14 Jun 2011 12:52:25 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1785#comment-59989</guid> <description>I have a text file of IP addresses that I&#039;d like to sort, which might look something like this:
10.20.30.40 50 60.70.80.90 100
1.2.3.4 50 5.6.7.8 80
ab32::ff0:c23a 123 ff::ab12 80
192.168.1.1 80 123.45.67.89 123
I&#039;d like to sort on the first column of IP addresses, then the third column of IP addresses.  It doesn&#039;t matter if IPv4 comes before IPv6 or vice versa.
This sort method seems to work only for a text file containing a single column of IPv4 addresses.  It&#039;s a tough problem.  This is a start for me, and I&#039;ll have to do some trial and error and reading of &quot;man sort.&quot;  Any tips would be appreciated.
Thanks!</description> <content:encoded><![CDATA[<p>I have a text file of IP addresses that I&#8217;d like to sort, which might look something like this:</p><p>10.20.30.40 50 60.70.80.90 100<br
/> 1.2.3.4 50 5.6.7.8 80<br
/> ab32::ff0:c23a 123 ff::ab12 80<br
/> 192.168.1.1 80 123.45.67.89 123</p><p>I&#8217;d like to sort on the first column of IP addresses, then the third column of IP addresses.  It doesn&#8217;t matter if IPv4 comes before IPv6 or vice versa.</p><p>This sort method seems to work only for a text file containing a single column of IPv4 addresses.  It&#8217;s a tough problem.  This is a start for me, and I&#8217;ll have to do some trial and error and reading of &#8220;man sort.&#8221;  Any tips would be appreciated.</p><p>Thanks!</p> ]]></content:encoded> </item> <item><title>By: Kacak</title><link>http://www.cyberciti.biz/faq/unix-linux-shell-script-sorting-ip-addresses/#comment-57273</link> <dc:creator>Kacak</dc:creator> <pubDate>Thu, 14 Apr 2011 06:54:49 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1785#comment-57273</guid> <description>Thanks for the great sharing... I know this is for unix/linux machine, but i would appreciate if you could share something similar (to sort ip addresses) on windows OS as well.
Thanks</description> <content:encoded><![CDATA[<p>Thanks for the great sharing&#8230; I know this is for unix/linux machine, but i would appreciate if you could share something similar (to sort ip addresses) on windows OS as well.</p><p>Thanks</p> ]]></content:encoded> </item> <item><title>By: Vivek Umasuthan</title><link>http://www.cyberciti.biz/faq/unix-linux-shell-script-sorting-ip-addresses/#comment-44870</link> <dc:creator>Vivek Umasuthan</dc:creator> <pubDate>Tue, 24 Nov 2009 21:14:17 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1785#comment-44870</guid> <description>This was really useful. Thanks for the help.</description> <content:encoded><![CDATA[<p>This was really useful. Thanks for the help.</p> ]]></content:encoded> </item> <item><title>By: Brad</title><link>http://www.cyberciti.biz/faq/unix-linux-shell-script-sorting-ip-addresses/#comment-44127</link> <dc:creator>Brad</dc:creator> <pubDate>Fri, 16 Oct 2009 19:57:26 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1785#comment-44127</guid> <description>You allude to sorting all columns in an IP address, but don&#039;t specifically state how to.
Here&#039;s the sort command to sort all IP addresses:
sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n /path/to/file
Also, since i&#039;m here, i wanted then to reverse my IP addresses so i could build a reverse zone file for DNS. I found an easy way:
IP=10.120.19.18
IP=(${IP//./ })
Rev=${IP[3]}.${IP[2]}.${IP[1]}.${IP[0]}
echo $Rev
Thanks to you and your sort command for getting me started.</description> <content:encoded><![CDATA[<p>You allude to sorting all columns in an IP address, but don&#8217;t specifically state how to.<br
/> Here&#8217;s the sort command to sort all IP addresses:<br
/> sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n /path/to/file</p><p>Also, since i&#8217;m here, i wanted then to reverse my IP addresses so i could build a reverse zone file for DNS. I found an easy way:<br
/> IP=10.120.19.18<br
/> IP=(${IP//./ })<br
/> Rev=${IP[3]}.${IP[2]}.${IP[1]}.${IP[0]}<br
/> echo $Rev</p><p>Thanks to you and your sort command for getting me started.</p> ]]></content:encoded> </item> <item><title>By: Raymond</title><link>http://www.cyberciti.biz/faq/unix-linux-shell-script-sorting-ip-addresses/#comment-38796</link> <dc:creator>Raymond</dc:creator> <pubDate>Wed, 17 Sep 2008 15:01:28 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1785#comment-38796</guid> <description>I&#039;ve been follow your site 6 months, faq section is always very informative. keep up your good work..</description> <content:encoded><![CDATA[<p>I&#8217;ve been follow your site 6 months, faq section is always very informative. keep up your good work..</p> ]]></content:encoded> </item> <item><title>By: Vaishnavi</title><link>http://www.cyberciti.biz/faq/unix-linux-shell-script-sorting-ip-addresses/#comment-38792</link> <dc:creator>Vaishnavi</dc:creator> <pubDate>Wed, 17 Sep 2008 10:20:45 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1785#comment-38792</guid> <description>A very good example. Your site is amazing and I look forward to your posts all the time :)</description> <content:encoded><![CDATA[<p>A very good example. Your site is amazing and I look forward to your posts all the time :)</p> ]]></content:encoded> </item> </channel> </rss>
