<?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>greynode &#187; awk</title>
	<atom:link href="http://greynode.org/tag/awk/feed/" rel="self" type="application/rss+xml" />
	<link>http://greynode.org</link>
	<description>ingénierie de tous les aspects de vie</description>
	<lastBuildDate>Wed, 11 Aug 2010 04:10:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Functional Programming with the Unix Command Line</title>
		<link>http://greynode.org/2009/06/25/functional-programming-with-the-unix-command-line/</link>
		<comments>http://greynode.org/2009/06/25/functional-programming-with-the-unix-command-line/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 06:29:30 +0000</pubDate>
		<dc:creator>Jeff Aigner</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[functional]]></category>
		<category><![CDATA[one liners]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scripting languages]]></category>

		<guid isPermaLink="false">http://greynode.org/?p=66</guid>
		<description><![CDATA[I was pondering the unix command line the other day while reading sed &#38; awk, and I came to the following revelation: variables aside, the unix command line is a lot like functional programming. Using the command line, you can build a functional program by redirecting I/O between various programs, or functions. Many of the [...]]]></description>
			<content:encoded><![CDATA[<p>I was pondering the unix command line the other day while reading <em>sed &amp; awk</em>, and I came to the following revelation: variables aside, the unix command line is a lot like functional programming. Using the command line, you can build a functional program by redirecting I/O between various programs, or <em>functions</em>. Many of the programs one uses to build one-liners are essentially <a href="http://en.wikipedia.org/wiki/Pure_function"><strong>pure functions</strong></a>. An example of a pure function on the unix command line might be the programs <em>uniq</em> or <em>sort</em>. Various other functions such as <em>ps</em> and <em>wget</em> are not so pure, as their output relies on I/O with the operating sytem or server.</p>
<p>All theory aside, here are a few good one-liners.</p>
<h2>Uploading Files</h2>
<blockquote>
<pre>tar cjvf - yourDirectory | ssh uname@host "cat &gt; yourDirectory.tar.bz2"</pre>
</blockquote>
<p>This command will create an archive of &#8220;yourDirectory&#8221; and upload it to your server via SSH, all in one chained command. Quite handy for uploading local content for sharing or backup.</p>
<p><strong>Edit:</strong> Apparently this command transfers large files extremely slow. Oops.</p>
<h2>Checking FreeBSD UPDATING File Automatically</h2>
<blockquote>
<pre>portversion | awk '/&lt;/ {print $1}' |
xargs -I '{}' awk '/AFFECTS:.*{}/ {print}' /usr/ports/UPDATING &gt; updates.txt</pre>
</blockquote>
<p>Ok. So this command pertains to the FreeBSD ports system. It is not recommended that you upgrade all your ports at once. There is often information contained in the file /usr/ports/UPDATING about special instructions you may have to follow while upgrading a package. Often times you may have to recompile other packages, or add a line to a configuration file, etc. The string above will check all of the ports tht are out of date, and compare them to the UPDATING file to see if the package is contained. If it is, it writes the name of that port to updates.txt. You can then use this file to know which ports have special instructions. You should probably write an alias for this one.</p>
<h2>Converting Line Endings</h2>
<p>The following two commands should help with reformatting files. Often times I find myself getting web designs from someone who uses windows. Most editors on windows will save files with DOS line endings. When you open one of these files in unix (in certain editors), the line endings won&#8217;t appear properly. The following commands will circumvent this problem, in either situation.</p>
<h3>Convert from unix (\n) to DOS (\r\n)</h3>
<blockquote>
<pre>awk '{sub(/$/, "\r")};1' unix_endings.txt &gt; dos_endings.txt</pre>
</blockquote>
<h3>Convert from DOS (\r\n) to unix (\n)</h3>
<blockquote>
<pre>awk '{sub(/\r$/, "")};1' dos_endings.txt &gt; unix_endings.txt</pre>
</blockquote>
<p>And yes, I realize that I use too many commas when I write: I&#8217;m working on it.</p>
]]></content:encoded>
			<wfw:commentRss>http://greynode.org/2009/06/25/functional-programming-with-the-unix-command-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scripting Languages</title>
		<link>http://greynode.org/2009/06/22/scripting-languages/</link>
		<comments>http://greynode.org/2009/06/22/scripting-languages/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 22:02:04 +0000</pubDate>
		<dc:creator>Jeff Aigner</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[GNU]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scripting languages]]></category>

		<guid isPermaLink="false">http://www.greynode.org/?p=48</guid>
		<description><![CDATA[I just thought I&#8217;d share with you Random thoughts on scripting languages by Brian Kernighan. After reading this, I looked up the source code to the unix utility wc. The GNU wc program was written in C, and amounted to about 800 lines with comments. A similar program written in awk is a mere 2 [...]]]></description>
			<content:encoded><![CDATA[<p>I just thought I&#8217;d share with you <a title="Random thoughts on scripting languages by Brian Kernighan" href="http://www.greynode.org/pdf/CS152-Lecture_14-Kernighan.pdf">Random thoughts on scripting languages by Brian Kernighan</a>.</p>
<p>After reading this, I looked up the <a title="source code for coreutils" href="http://www.gnu.org/software/coreutils/">source code to the unix utility wc</a>. The GNU <em>wc</em> program was written in C, and amounted to about 800 lines with comments. A similar program written in <a title="awk" href="http://www.gnu.org/manual/gawk/gawk.html"><strong>awk</strong></a> is a mere 2 lines long:</p>
<blockquote>
<pre>{ nc += length($0) + 1; nw += NF }
END { print NR, "lines", nw, "words", nc, "characters" }</pre>
</blockquote>
<p>I know you are probably thinking that I just made an unfair comparison. Yes, I did.</p>
]]></content:encoded>
			<wfw:commentRss>http://greynode.org/2009/06/22/scripting-languages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->