<?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: Sort CLI output by line length</title>
	<atom:link href="http://www.linuxscrew.com/2009/04/14/sort-cli-output-by-line-length/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.linuxscrew.com/2009/04/14/sort-cli-output-by-line-length/</link>
	<description></description>
	<lastBuildDate>Fri, 10 Feb 2012 06:51:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=871</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: squash</title>
		<link>http://www.linuxscrew.com/2009/04/14/sort-cli-output-by-line-length/comment-page-1/#comment-481750</link>
		<dc:creator>squash</dc:creator>
		<pubDate>Wed, 27 Apr 2011 19:25:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.linuxscrew.com/?p=767#comment-481750</guid>
		<description>Good write-up. I am a normal visitor of your blog and appreciate you taking the time to maintain the nice site. I&#039;ll be a regular visitor for a really long time.</description>
		<content:encoded><![CDATA[<p>Good write-up. I am a normal visitor of your blog and appreciate you taking the time to maintain the nice site. I&#8217;ll be a regular visitor for a really long time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Trying to write a script to sort pairs of lines by the length of the 2nd in the pair</title>
		<link>http://www.linuxscrew.com/2009/04/14/sort-cli-output-by-line-length/comment-page-1/#comment-111746</link>
		<dc:creator>Trying to write a script to sort pairs of lines by the length of the 2nd in the pair</dc:creator>
		<pubDate>Wed, 02 Jun 2010 18:30:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.linuxscrew.com/?p=767#comment-111746</guid>
		<description>[...] http://www.linuxscrew.com/2009/04/14...y-line-length/ this may help,..  there are plenty of sorting algorithms in case that you have a lot of lines. use awk to get first string in each line, to remove header use substring command [...]</description>
		<content:encoded><![CDATA[<p>[...] <a href="http://www.linuxscrew.com/2009/04/14...y-line-length/" rel="nofollow">http://www.linuxscrew.com/2009/04/14&#8230;y-line-length/</a> this may help,..  there are plenty of sorting algorithms in case that you have a lot of lines. use awk to get first string in each line, to remove header use substring command [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: WARLOCKMAN</title>
		<link>http://www.linuxscrew.com/2009/04/14/sort-cli-output-by-line-length/comment-page-1/#comment-45697</link>
		<dc:creator>WARLOCKMAN</dc:creator>
		<pubDate>Mon, 19 Oct 2009 15:40:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.linuxscrew.com/?p=767#comment-45697</guid>
		<description>????… ??????? ??????? ????????! ??? ??? ??? ???????…? ????????!</description>
		<content:encoded><![CDATA[<p>????… ??????? ??????? ????????! ??? ??? ??? ???????…? ????????!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pierre Relation</title>
		<link>http://www.linuxscrew.com/2009/04/14/sort-cli-output-by-line-length/comment-page-1/#comment-36725</link>
		<dc:creator>Pierre Relation</dc:creator>
		<pubDate>Tue, 23 Jun 2009 12:35:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.linuxscrew.com/?p=767#comment-36725</guid>
		<description>Oh, don&#039;t worry about the tabs going away. We figured it out just as well. It works indeed like that so thanks for sharing!</description>
		<content:encoded><![CDATA[<p>Oh, don&#8217;t worry about the tabs going away. We figured it out just as well. It works indeed like that so thanks for sharing!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ubuntuverse</title>
		<link>http://www.linuxscrew.com/2009/04/14/sort-cli-output-by-line-length/comment-page-1/#comment-35929</link>
		<dc:creator>ubuntuverse</dc:creator>
		<pubDate>Thu, 18 Jun 2009 14:56:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.linuxscrew.com/?p=767#comment-35929</guid>
		<description>ruby hackers way :)

ruby -e &quot;puts File.open(&#039;/etc/passwd&#039;).sort { &#124;a,b&#124; a.length  b.length }&quot;</description>
		<content:encoded><![CDATA[<p>ruby hackers way <img src='http://www.linuxscrew.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>ruby -e &#8220;puts File.open(&#8216;/etc/passwd&#8217;).sort { |a,b| a.length  b.length }&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Phil</title>
		<link>http://www.linuxscrew.com/2009/04/14/sort-cli-output-by-line-length/comment-page-1/#comment-33847</link>
		<dc:creator>Phil</dc:creator>
		<pubDate>Tue, 02 Jun 2009 05:38:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.linuxscrew.com/?p=767#comment-33847</guid>
		<description>Well, it was clearer &#039;till the tabs all went away.  

;&gt;)</description>
		<content:encoded><![CDATA[<p>Well, it was clearer &#8217;till the tabs all went away.  </p>
<p>;&gt;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Phil</title>
		<link>http://www.linuxscrew.com/2009/04/14/sort-cli-output-by-line-length/comment-page-1/#comment-33846</link>
		<dc:creator>Phil</dc:creator>
		<pubDate>Tue, 02 Jun 2009 05:37:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.linuxscrew.com/?p=767#comment-33846</guid>
		<description>You don&#039;t need the cat invocation. Awk can take the file as the standard input. 
So, the following works just as well:

 awk &#039;{print length, $0}&#039; /etc/passwd &#124; sort -n &#124; awk &#039;{$1=&quot;&quot;; print $0 }&#039; 


You can put the length of the line into an associative array and sort it all from within awk. Interesting associative array play:

awk &#039;{ arr[length $0] = $0 } END { for (len in arr) \
printf(&quot;%d\t%s\n&quot;, len, arr[len])  &#124; &quot;sort -n&quot; }&#039; /etc/passwd &#124; cut -f2-

In script form it&#039;s a bit clearer:

#!/bin/bash
# awksort: sort the input by size
 
awk &#039;{ 
  arr[length $0] = $0 
} 
END { 
  for (len in arr) 
    printf(&quot;%d\t%s\n&quot;, len, arr[len]) &#124; &quot;sort -n&quot; 
}&#039; $*   &#124;
 
cut -f2-


Invoked with:

# awksort /etc/passwd</description>
		<content:encoded><![CDATA[<p>You don&#8217;t need the cat invocation. Awk can take the file as the standard input.<br />
So, the following works just as well:</p>
<p> awk &#8216;{print length, $0}&#8217; /etc/passwd | sort -n | awk &#8216;{$1=&#8221;"; print $0 }&#8217; </p>
<p>You can put the length of the line into an associative array and sort it all from within awk. Interesting associative array play:</p>
<p>awk &#8216;{ arr[length $0] = $0 } END { for (len in arr) \<br />
printf(&#8220;%d\t%s\n&#8221;, len, arr[len])  | &#8220;sort -n&#8221; }&#8217; /etc/passwd | cut -f2-</p>
<p>In script form it&#8217;s a bit clearer:</p>
<p>#!/bin/bash<br />
# awksort: sort the input by size</p>
<p>awk &#8216;{<br />
  arr[length $0] = $0<br />
}<br />
END {<br />
  for (len in arr)<br />
    printf(&#8220;%d\t%s\n&#8221;, len, arr[len]) | &#8220;sort -n&#8221;<br />
}&#8217; $*   |</p>
<p>cut -f2-</p>
<p>Invoked with:</p>
<p># awksort /etc/passwd</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MGMGrandDetroit</title>
		<link>http://www.linuxscrew.com/2009/04/14/sort-cli-output-by-line-length/comment-page-1/#comment-30464</link>
		<dc:creator>MGMGrandDetroit</dc:creator>
		<pubDate>Mon, 04 May 2009 17:45:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.linuxscrew.com/?p=767#comment-30464</guid>
		<description>Very interesting, thanks for the information.</description>
		<content:encoded><![CDATA[<p>Very interesting, thanks for the information.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: LouisianaPowerballNumbers</title>
		<link>http://www.linuxscrew.com/2009/04/14/sort-cli-output-by-line-length/comment-page-1/#comment-30185</link>
		<dc:creator>LouisianaPowerballNumbers</dc:creator>
		<pubDate>Fri, 01 May 2009 13:29:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.linuxscrew.com/?p=767#comment-30185</guid>
		<description>Very good</description>
		<content:encoded><![CDATA[<p>Very good</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: LottoZheroGravity</title>
		<link>http://www.linuxscrew.com/2009/04/14/sort-cli-output-by-line-length/comment-page-1/#comment-30154</link>
		<dc:creator>LottoZheroGravity</dc:creator>
		<pubDate>Fri, 01 May 2009 00:21:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.linuxscrew.com/?p=767#comment-30154</guid>
		<description>Interesting, thanks for the post.</description>
		<content:encoded><![CDATA[<p>Interesting, thanks for the post.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic page generated in 0.221 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-02-10 09:54:14 -->

