<?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>cat brain.log &#124; less &#187; awk</title>
	<atom:link href="http://log.largevoid.com/tag/awk/feed/" rel="self" type="application/rss+xml" />
	<link>http://log.largevoid.com</link>
	<description>Getting it down on `paper`</description>
	<lastBuildDate>Mon, 06 Feb 2012 06:23:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Periodic Tarballs: Find and Awk</title>
		<link>http://log.largevoid.com/2010/06/periodic-tarballs-find-and-awk/</link>
		<comments>http://log.largevoid.com/2010/06/periodic-tarballs-find-and-awk/#comments</comments>
		<pubDate>Wed, 02 Jun 2010 08:43:04 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[Scripts, Tricks and Hacks]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[cut]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[gzip]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[pipe]]></category>
		<category><![CDATA[tar]]></category>

		<guid isPermaLink="false">http://log.largevoid.com/?p=355</guid>
		<description><![CDATA[I have a gang of directories. There&#8217;s a new directory each day! Each directory stores about 20k files. Over time, the performance of the directory hierarchy degrades, and it&#8217;s best for me to tar up old stuff. In linux-land, there&#8217;s always more than one way of doing things&#8230; even if it&#8217;s not the right way. [...]]]></description>
			<content:encoded><![CDATA[<p>I have a gang of directories.  There&#8217;s a new directory each day!  Each directory stores about 20k files.  Over time, the performance of the directory hierarchy degrades, and it&#8217;s best for me to tar up old stuff.</p>
<p>In linux-land, there&#8217;s always more than one way of doing things&#8230; even if it&#8217;s not the right way.  Today, we&#8217;ll explore find piped to awk piped to the shell.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">touch</span> . ; <span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-type</span> d <span style="color: #660033;">-maxdepth</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-mtime</span> +<span style="color: #000000;">60</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #000000; font-weight: bold;">|</span>
<span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span><span style="color: #ff0000;">&quot;/&quot;</span> <span style="color: #ff0000;">'{print &quot;tar czf &quot; $2 &quot;.tar.gz --remove-files ./&quot; $2 &quot;; rmdir &quot; $2 }'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sh</span></pre></div></div>

<p>Basically, make sure the current direction has been recently modified, so it&#8217;s not returned by the find command.  Then, find all sub-directories in the current directory &#8212; don&#8217;t go recursive.  Sort for a predictable sequence of operations.  Extract the file name portion (lots of ways to do this).  Generate a shell command <code>tar czf {{dirname}}.tar.gz --remove-files ./{{dirname}}; rmdir {{dirname}}</code> to build the tarball and remove the empty directory when done.  Finally, we just tell <code>sh</code> to execute it all&#8230; one directory at a time. Bam!</p>
]]></content:encoded>
			<wfw:commentRss>http://log.largevoid.com/2010/06/periodic-tarballs-find-and-awk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Summing a list of numbers</title>
		<link>http://log.largevoid.com/2009/10/summing-a-list-of-numbers/</link>
		<comments>http://log.largevoid.com/2009/10/summing-a-list-of-numbers/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 02:00:40 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[Scripts, Tricks and Hacks]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://log.largevoid.com/?p=10</guid>
		<description><![CDATA[awk '{sum += $0} END {print sum}' Example: % find . -type f -exec wc {} \; &#124; tr -s " " &#124; cut -f2 -d" " &#124; awk '{sum += $0} END {print sum}' What’s going on? I want to recursively count the number of lines present in all files contained by the current [...]]]></description>
			<content:encoded><![CDATA[<p><code>awk '{sum += $0} END {print sum}'</code></p>
<p>Example:<code><br />
% find . -type f -exec wc {} \; | tr -s " " | cut -f2 -d" " | awk '{sum += $0} END {print sum}'</code></p>
<p>What’s going on? I want to recursively count the number of lines present in all files contained by the current directory. Why? Sub-directories =&gt; namespaces, and I want to know how many lines of code exist in the entire project, namespaces and all.</p>
]]></content:encoded>
			<wfw:commentRss>http://log.largevoid.com/2009/10/summing-a-list-of-numbers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  log.largevoid.com/tag/awk/feed/ ) in 0.23718 seconds, on Feb 8th, 2012 at 3:45 am UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 8th, 2012 at 4:45 am UTC -->
