<?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/"
	>

<channel>
	<title>BrainMedley &#187; Unix</title>
	<atom:link href="http://brainmedley.com/blog/category/unix/feed/" rel="self" type="application/rss+xml" />
	<link>http://brainmedley.com/blog</link>
	<description>A varied mixture of people or things; a miscellany</description>
	<lastBuildDate>Tue, 31 Mar 2009 06:15:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>I am uniq</title>
		<link>http://brainmedley.com/blog/2008/06/i-am-uniq/</link>
		<comments>http://brainmedley.com/blog/2008/06/i-am-uniq/#comments</comments>
		<pubDate>Sun, 15 Jun 2008 21:40:09 +0000</pubDate>
		<dc:creator>brain</dc:creator>
				<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://brainmedley.com/blog/?p=32</guid>
		<description><![CDATA[[Republished from October 2005 from my previous site]
Two of the things I love most about unix are learning new tools and tricks and teaching tools and tricks to others.  One of unix&#8217;s real gems is uniq(1): &#8220;report or filter out repeated lines in a file&#8221;.  Extremely simple and powerful, probably a page or two [...]]]></description>
			<content:encoded><![CDATA[<p>[Republished from October 2005 from my <a href="http://tinker.pbwiki.com/Blog10Oct2005">previous site</a>]</p>
<p>Two of the things I love most about unix are learning new tools and tricks and teaching tools and tricks to others.  One of unix&#8217;s real gems is <code>uniq(1)</code>: &#8220;report or filter out repeated lines in a file&#8221;.  Extremely simple and powerful, probably a page or two of easy code, but completely indispensable.<span id="more-32"></span>  I usually use it to get the intersections or differences of lists using the <code>-d</code> and <code>-u</code> options.  Intersection is pretty straightforward:</p>
<pre>  cat list_one.txt list_two.txt | sort | uniq -d</pre>
<p>Basically, <code>cat</code> the two lists together (incidentally creating the union, with duplicates), <code>sort</code> that (because <code>uniq</code> only checks adjacent lines, so duplicates have to be next to each other) then have <code>uniq</code> print only the duplicated lines (ok, yeah, you need to be sure neither list has any duplicates to start out with)</p>
<p>Getting a strict difference is a little tricker, you actually have to get the intersection first and then remove those elements using a second pass:</p>
<pre>  cat list_one.txt list_two.txt | sort | uniq -d | cat list_one.txt - | sort | uniq -u</pre>
<p>Will return the elements of &#8221;list_one.txt&#8221; that do not appear in &#8221;list_two.txt&#8221; (Note the <code>-</code> argument to the second <code>cat</code>, which signifies standard input and receives the | &#8211; <code>cat</code> is worthy of its own entry sometime, though)</p>
]]></content:encoded>
			<wfw:commentRss>http://brainmedley.com/blog/2008/06/i-am-uniq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
