<?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>dragffy.com &#187; scripts</title>
	<atom:link href="http://dragffy.com/blog/posts/tag/scripts/feed" rel="self" type="application/rss+xml" />
	<link>http://dragffy.com/blog</link>
	<description>The development, documentation, and blogging domain of Gabriel Dragffy.</description>
	<lastBuildDate>Sun, 29 Apr 2012 11:55:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Grope, a Ruby script for enhanced Grepping</title>
		<link>http://dragffy.com/blog/posts/grope-a-ruby-script-for-enhanced-grepping</link>
		<comments>http://dragffy.com/blog/posts/grope-a-ruby-script-for-enhanced-grepping#comments</comments>
		<pubDate>Wed, 19 Mar 2008 17:56:54 +0000</pubDate>
		<dc:creator>Gabe</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Operating System]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[grope]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://dragffy.com/blog/posts/grope-a-ruby-script-for-enhanced-grepping</guid>
		<description><![CDATA[There was a time when I would recursively grep the contents of literally thousands of files at a time to search for particular occurances of characters. The usual starting place was something using grep, which we can time for crude benchmarking: user@localhost$ time grep -rn 'hello' * templates/temp.tpl:1:hello real 1m56.190s user 0m1.400s sys 0m0.940s Using [...]]]></description>
			<content:encoded><![CDATA[<p>There was a time when I would recursively grep the contents of literally thousands of files at a time to search for particular occurances of characters. The usual starting place was something using grep, which we can time for crude benchmarking:<br />
<code><br />
user@localhost$ time grep -rn 'hello' *<br />
templates/temp.tpl:1:hello</p>
<p>real    1m56.190s<br />
user    0m1.400s<br />
sys     0m0.940s<br />
</code></p>
<p>Using Ruby to write a script, which I named Grope, I made the search process 450 times faster, reducing an operation that took more than a minute to taking a blink of an eye&#8230;<br />
<code><br />
user@localhost$ time grope 'hello'<br />
templates/festival/06/temp.tpl: 1<br />
hello...</p>
<p>real    0m0.181s<br />
user    0m0.100s<br />
sys     0m0.070s<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://dragffy.com/blog/posts/grope-a-ruby-script-for-enhanced-grepping/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby script for replacing tab delimeters with commas</title>
		<link>http://dragffy.com/blog/posts/ruby-script-for-replacing-tab-delimeters-with-commas</link>
		<comments>http://dragffy.com/blog/posts/ruby-script-for-replacing-tab-delimeters-with-commas#comments</comments>
		<pubDate>Tue, 11 Mar 2008 13:21:32 +0000</pubDate>
		<dc:creator>Gabe</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">http://dragffy.com/blog/posts/ruby-script-for-replacing-tab-delimeters-with-commas</guid>
		<description><![CDATA[A trivial Ruby script for replacing any number of tabs in input.csv with a single comma and then writing it as output.csv. The first version works from the command line and makes use of concatenating a file and piping it to a ruby command which then diverts the output in to a file, a one [...]]]></description>
			<content:encoded><![CDATA[<p>A trivial Ruby script for replacing any number of tabs in <code>input.csv</code> with a single comma and then writing it as <code>output.csv</code>.</p>
<p>The first version works from the command line and makes use of concatenating a file and piping it to a ruby command which then diverts the output in to a file, a one liner:<br />
<code>cat input.csv | ruby -pe 'gsub( /\t+/, "," )' &gt; output.csv</code></p>
<p>This can be further enhanced by using the in-place-edit switch of the Ruby interpreter, editing the <code>input.csv</code> file and leaving a pristine copy with .bak extension.<br />
<code>ruby -i.bak -pe 'gsub( /\t+/, "," )' input.csv<br />
</code></p>
<p><code></code><br />
The final version is what you might put in to a Ruby file. Although the input and output files are hard-coded, it would be trivial to allow them to be specified on the command line.</p>
<pre>
#!/usr/bin/env ruby

# Initialise a new file object that is writable
file = File.new( "output.csv", "w" )

# Open the existing tab delimited file and read each line
File.open( "input.csv", "r" ).each do |line|
  # Perform a global substitution of tabs with commas and
  # put that in the new file
  file.puts line.gsub( /\t+/, "," )
end

# Tidy up by closing the newly written output file.
file.close</pre>
]]></content:encoded>
			<wfw:commentRss>http://dragffy.com/blog/posts/ruby-script-for-replacing-tab-delimeters-with-commas/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

