<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Miscinformation</title>
	<atom:link href="http://miscinformation.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://miscinformation.wordpress.com</link>
	<description></description>
	<lastBuildDate>Mon, 14 Jul 2008 19:21:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='miscinformation.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Miscinformation</title>
		<link>http://miscinformation.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://miscinformation.wordpress.com/osd.xml" title="Miscinformation" />
	<atom:link rel='hub' href='http://miscinformation.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Intro to sort</title>
		<link>http://miscinformation.wordpress.com/2008/07/13/intro-to-sort/</link>
		<comments>http://miscinformation.wordpress.com/2008/07/13/intro-to-sort/#comments</comments>
		<pubDate>Sun, 13 Jul 2008 07:48:30 +0000</pubDate>
		<dc:creator>miscinformation</dc:creator>
				<category><![CDATA[unix]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://miscinformation.wordpress.com/?p=6</guid>
		<description><![CDATA[The sort command will sort the lines in a text file according to various criteria. The default sort order is ASCII character order, which has punctuation characters first, then numbers, then upper case letters, then lower case letters. Example of an unsorted file: $ cat file1 sarah . John 7 carol Claire eric 43 , [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=miscinformation.wordpress.com&amp;blog=4204290&amp;post=6&amp;subd=miscinformation&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The sort command will sort the lines in a text file according to various criteria.  The default sort order is <a href="http://en.wikipedia.org/wiki/ASCII">ASCII</a> character order, which has punctuation characters first, then numbers, then upper case letters, then lower case letters.</p>
<p>Example of an unsorted file:</p>
<pre>$ cat file1
sarah
.
John
7
carol
Claire
eric
43
,</pre>
<p>Sorting the file:</p>
<pre>$ sort file1
,
.
43
7
Claire
John
carol
eric
sarah</pre>
<p><span id="more-6"></span></p>
<p>Note that 43 comes before 7.  This is because sort is not comparing them as numbers, but it is sorting them according to the ASCII character order.  4 comes before 7 in the ASCII character order, so any string starting with a 4 will come before any string starting with a 7.</p>
<p>To sort a file numerically, you would use the -n option.</p>
<p>File containing numbers:</p>
<pre>$ cat num1
100
3
47658
23
8
2398</pre>
<p>Default (ASCII order) sort:</p>
<pre>$ sort num1
100
23
2398
3
47658
8</pre>
<p>Numeric sort:</p>
<pre>$ sort -n num1
3
8
23
100
2398
47658</pre>
<h2>Real Life Example</h2>
<p>A common use of numeric sort is seeing what files or directories are using the most space.</p>
<p>Checking disk usage:</p>
<pre>$ du -sk *
39232   bin
238     list.txt
92876   mail
1623    notes
864328  photos</pre>
<p>Sorting disk usage:</p>
<pre>$ du -sk * | sort -n
238     list.txt
1623    notes
39232   bin
92876   mail
864328  photos</pre>
<p>Or you can use the -r flag in conjunction with the -n flag to sort in reverse numeric order:</p>
<pre>$ du -sk * | sort -rn
864328  photos
92876   mail
39232   bin
1623    notes
238     list.txt</pre>
<h2>Summary</h2>
<p>The sort command will sort a file according to ASCII character order by default.  Use -n to sort by numeric value.  Use -r to reverse the order of a sort.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/miscinformation.wordpress.com/6/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/miscinformation.wordpress.com/6/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/miscinformation.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/miscinformation.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/miscinformation.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/miscinformation.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/miscinformation.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/miscinformation.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/miscinformation.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/miscinformation.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/miscinformation.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/miscinformation.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/miscinformation.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/miscinformation.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/miscinformation.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/miscinformation.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=miscinformation.wordpress.com&amp;blog=4204290&amp;post=6&amp;subd=miscinformation&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://miscinformation.wordpress.com/2008/07/13/intro-to-sort/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3240c1a682a7eafbf997cca622382528?s=96&#38;d=identicon" medium="image">
			<media:title type="html">miscinformation</media:title>
		</media:content>
	</item>
	</channel>
</rss>
