<?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; one liners</title>
	<atom:link href="http://greynode.org/tag/one-liners/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>Replace Text Recursively with sed</title>
		<link>http://greynode.org/2009/06/17/replace-text-recursively-with-sed/</link>
		<comments>http://greynode.org/2009/06/17/replace-text-recursively-with-sed/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 20:53:31 +0000</pubDate>
		<dc:creator>Jeff Aigner</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[one liners]]></category>

		<guid isPermaLink="false">http://www.greynode.org/?p=45</guid>
		<description><![CDATA[Here is a quick little trick I discovered today when I needed to replace text in multiple files recursively: grep -rl -e &#60;searchterm&#62; * &#124; xargs sed -i .bak 's/searchterm/newterm/i' There might be a problem with files that have spaces in the names (because xargs will take a space as the start of a new [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a quick little trick I discovered today when I needed to replace text in multiple files recursively:</p>
<blockquote>
<pre>grep -rl -e &lt;searchterm&gt; * | xargs sed -i .bak 's/searchterm/newterm/i'</pre>
</blockquote>
<p>There might be a problem with files that have spaces in the names (because xargs will take a space as the start of a new argument). To solve this problem, you should be able to do something like this:</p>
<blockquote>
<pre>grep -rl --null -e &lt;searchterm&gt; * |</pre>
<pre>xargs -0 sed -i .bak 's/searchterm/newterm/i'</pre>
</blockquote>
<p>If you are using GNU grep, you could also use -Z instead of &#8211;null. I happen to be using the BSD version of grep, so -Z isn&#8217;t an alias for &#8211;null.</p>
]]></content:encoded>
			<wfw:commentRss>http://greynode.org/2009/06/17/replace-text-recursively-with-sed/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! -->