<?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/"
	xmlns:media="http://search.yahoo.com/mrss"
>

<channel>
	<title>Deep Thoughts by Robert Felty &#187; linux</title>
	<atom:link href="http://blog.robfelty.com/category/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.robfelty.com</link>
	<description>thoughts on wordpress, latex, cooking et alia</description>
	<lastBuildDate>Wed, 04 Aug 2010 21:56:13 +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>Editing video from a Canon FS100 with Kino and ffmpeg</title>
		<link>http://blog.robfelty.com/2009/04/25/editing-video-from-a-canon-fs100-with-kino-and-ffmpeg/</link>
		<comments>http://blog.robfelty.com/2009/04/25/editing-video-from-a-canon-fs100-with-kino-and-ffmpeg/#comments</comments>
		<pubDate>Sat, 25 Apr 2009 14:38:59 +0000</pubDate>
		<dc:creator>robfelty</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[ffmpeg]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://blog.robfelty.com/?p=302</guid>
		<description><![CDATA[Last Christmas my parents got me a Canon FS100 video camera. I had asked for a video camera to take videos of my son. I honed my video editing skills a bit before he arrived, but am still working on it. The camera uses flash memory, and records videos in .mod files, which are basically [...]]]></description>
			<content:encoded><![CDATA[<p>Last Christmas my parents got me a Canon FS100 video camera. I had asked for a video camera to take videos of my son. I honed my video editing skills a bit before he arrived, but am still working on it. The camera uses flash memory, and records videos in .mod files, which are basically just .mpg files. Although the camera is not HD (the HD version was more than twice as expensive), it does have the option of recording in 16:9 widescreen. I have been using Kino to do my editing, with some success. One problem I had was that if I used Kino to import the files from the camera, the aspect ratio got messed up. Kino would treat the file as 4:3 aspect ratio, even though I had the settings to 16:9. Then it would pad the sides with black space. I saw others complaining about this problem as well, but did not find anyone with a solution. Eventually, I decided to try my hand with ffmpeg myself. After some playing around, I determined that I could create a dv file from the .mod file with ffmpeg, open the .dv with Kino, do some editing, export, and then convert again. </p>
<p>First the conversion from .mod to .dv</p>
<div class="codecolorer-container bash dawn" style="overflow:auto;white-space:nowrap;width:100"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw2">ffmpeg</span> <span class="re5">-i</span> MOV001.MOD <span class="re5">-target</span> dv <span class="re5">-aspect</span> <span class="nu0">16</span>:<span class="nu0">9</span> MOV001.dv</div></div>
<p>Then I open the .dv file in Kino and edit it, and export to raw dv, making sure to uncheck the options for splitting into separate files and for resampling audio</p>
<p>Finally, I convert the dv to flv to put on my blog:</p>
<div class="codecolorer-container bash dawn" style="overflow:auto;white-space:nowrap;width:100"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw2">ffmpeg</span> <span class="re5">-i</span> infile.dv <span class="re5">-b</span> 325k <span class="re5">-ar</span> <span class="nu0">22050</span> <span class="re5">-ab</span> 24k <span class="re5">-s</span> 480x270 <span class="re5">-aspect</span> <span class="nu0">16</span>:<span class="nu0">9</span> outfile.flv</div></div>
<p>You can see the result on the <a href='http://blog.fedibblety.com/archives.php/2009/04/25/cooing-in-the-bumbo-chaircooing-in-the-bumbo-chair/'>fedibblety blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.robfelty.com/2009/04/25/editing-video-from-a-canon-fs100-with-kino-and-ffmpeg/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Reading iptc captions from jpegs with imagemagick</title>
		<link>http://blog.robfelty.com/2009/03/15/reading-iptc-captions-from-jpegs-with-imagemagick/</link>
		<comments>http://blog.robfelty.com/2009/03/15/reading-iptc-captions-from-jpegs-with-imagemagick/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 16:38:29 +0000</pubDate>
		<dc:creator>robfelty</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[photography]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[caption]]></category>
		<category><![CDATA[imagemagick]]></category>
		<category><![CDATA[iptc]]></category>
		<category><![CDATA[picasa]]></category>
		<category><![CDATA[postie]]></category>

		<guid isPermaLink="false">http://blog.robfelty.com/?p=257</guid>
		<description><![CDATA[Rob and Spencer with zebras Once again I found myself needing to use imagemagick to do something, and was overwhelmed by the many options. After much fiddling around, I found out some options that worked for me. In this case, I wanted to extract iptc captions from images, so that I could then insert the [...]]]></description>
			<content:encoded><![CDATA[<div class="imageframe alignleft" style="width:250px;"><a href="http://blog.robfelty.com/wp-content/uploads/2009/03/robspencer.jpg" title="Rob and Spencer with zebras"><img src="http://blog.robfelty.com/wp-content/uploads/2009/03/robspencer.jpg" alt="Rob and Spencer with zebras" width="250" class="attachment wp-att-258" /></a>
<div class="imagecaption">Rob and Spencer with zebras</div>
</div>
<p>Once again I found myself needing to use imagemagick to do something, and was overwhelmed by the many options. After much fiddling around, I found out some options that worked for me. </p>
<p>In this case, I wanted to extract iptc captions from images, so that I could then insert the caption in a webpage with php. I use Picasa to edit photos and add captions. Picasa adds in the captions in the iptc information, which is the right place to add them. To extract the caption from the image above, do the following</p>
<div class="codecolorer-container bash dawn" style="overflow:auto;white-space:nowrap;width:100"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace">convert robSpencer.jpg 8BIMTEXT:-</div></div>
<p>The result should be output to standard out:</p>
<blockquote><p>
8BIM#1028=&#8221;IPTC&#8221;<br />
2#120#Caption=&#8221;Rob and Spencer with zebras&#8221;
</p></blockquote>
<p>If you want to output to a file, simply do something like:</p>
<div class="codecolorer-container bash dawn" style="overflow:auto;white-space:nowrap;width:100"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace">convert robSpencer.jpg 8BIMTEXT:filename.iptc</div></div>
<p>Now it easy to extract the caption using perl, python, php or whatever you like. For perl, we could simply pipe it:</p>
<div class="codecolorer-container bash dawn" style="overflow:auto;white-space:nowrap;width:100"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace">convert robSpencer.jpg 8BIMTEXT:-<span class="sy0">|</span><span class="kw2">perl</span> <span class="re5">-ne</span> <span class="st_h">'/Caption=&quot;(.*)&quot;/; print $1;'</span></div></div>
<p>And in case you are interested, I needed to do this for the <a href='/plugins/postie'>postie wordpress plugin</a> which allows you to post to your blog via e-mail. In version 1.1.5 iptc captions will be read and displayed (if they are in the image you attach). </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.robfelty.com/2009/03/15/reading-iptc-captions-from-jpegs-with-imagemagick/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://blog.robfelty.com/wp-content/uploads/2009/03/robspencer.jpg" />
		<media:content url="http://blog.robfelty.com/wp-content/uploads/2009/03/robspencer.jpg" medium="image">
			<media:title type="html">Rob and Spencer with zebras</media:title>
		</media:content>
	</item>
		<item>
		<title>Picasa 3 collages</title>
		<link>http://blog.robfelty.com/2008/12/04/picasa-3-collages/</link>
		<comments>http://blog.robfelty.com/2008/12/04/picasa-3-collages/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 16:00:59 +0000</pubDate>
		<dc:creator>robfelty</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[photography]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[collage]]></category>
		<category><![CDATA[mediarss]]></category>
		<category><![CDATA[picasa]]></category>

		<guid isPermaLink="false">http://blog.robfelty.com/?p=174</guid>
		<description><![CDATA[thanksgiving collage I upgraded to Picasa 3 a couple weeks ago. I didn&#8217;t upgrade right away, because it took awhile for the linux version to come out. I can happily say that Picasa 3 works great under linux from my experience. It was easy to install (they had an rpm available), and it runs very [...]]]></description>
			<content:encoded><![CDATA[<div class="imageframe alignleft" style="width:250px;"><a href="http://blog.robfelty.com/wp-content/uploads/2008/12/thanksgiving.jpg" title="thanksgiving collage"><img src="http://blog.robfelty.com/wp-content/uploads/2008/12/thanksgiving.thumbnail.jpg" alt="thanksgiving collage" width="250" height="156" class="attachment wp-att-175" /></a>
<div class="imagecaption">thanksgiving collage</div>
</div>
<p>I upgraded to Picasa 3 a couple weeks ago. I didn&#8217;t upgrade right away, because it took awhile for the linux version to come out. I can happily say that Picasa 3 works great under linux from my experience. It was easy to install (they had an rpm available), and it runs very nicely. It seems like it even runs a bit faster than Picasa 2.6. But best of all, it has some really cool new features. One such feature is the ability to make collages. There was some rudimentary collage-making features in Picasa 2, but Picasa 3 adds lots of functionality. I decided to try it out recently with some pictures I took at Thanksgiving. I would say that my only complaint so far is that captions only seem to show up when you format the pictures as &#8220;polaroids&#8221;. It seems to be that if you include a white border, the caption should show up there. This was particularly frustrating because I had &#8220;show captions&#8221; box checked, but no captions were showing up. </p>
<p>I&#8217;ll also admit that part of the reason I wanted to write this post was because I just learned about mediarss, which is a way to include images, sound clips, and video clips in rss feeds. A quick google search for a wordpress plugin resulted in the <a href='http://wordpress.org/extend/plugins/mrss/'>media rss wordpress plugin</a>, which seems to be working. Now the only other question is whether or not it correctly shows up in my <a href='http://friendfeed.com/robfelty'>friendfeed</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.robfelty.com/2008/12/04/picasa-3-collages/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:thumbnail url="http://blog.robfelty.com/wp-content/uploads/2008/12/thanksgiving.thumbnail.jpg" />
		<media:content url="http://blog.robfelty.com/wp-content/uploads/2008/12/thanksgiving.thumbnail.jpg" medium="image">
			<media:title type="html">thanksgiving collage</media:title>
		</media:content>
	</item>
		<item>
		<title>Why doesn&#8217;t Mac update standard UNIX utilities?</title>
		<link>http://blog.robfelty.com/2008/09/15/why-doesnt-mac-update-standard-unix-utilities/</link>
		<comments>http://blog.robfelty.com/2008/09/15/why-doesnt-mac-update-standard-unix-utilities/#comments</comments>
		<pubDate>Mon, 15 Sep 2008 15:49:29 +0000</pubDate>
		<dc:creator>robfelty</dc:creator>
				<category><![CDATA[linguistics]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mac osx]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://blog.robfelty.com/?p=131</guid>
		<description><![CDATA[I am currently teaching a course on programming for linguists. We are using python, but for the first few classes, I have been going over some standard UNIX utilities like cd, ls and such, plus using regular expressions with grep and sed. I actually don&#8217;t use sed that much. I tend to reach for perl, [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently teaching a course on programming for linguists. We are using python, but for the first few classes, I have been going over some standard UNIX utilities like <tt>cd</tt>, <tt>ls</tt> and such, plus using regular expressions with <tt>grep</tt> and <tt>sed</tt>. I actually don&#8217;t use sed that much. I tend to reach for perl, since I know it better, and it can do pretty much all the same stuff that sed can plus much more. But sed is simpler than perl, and I basically just wanted to use it for doing substitutions. </p>
<p>Today I got an e-mail from a student asking why the following did not seem to be working:</p>
<div class="codecolorer-container bash dawn" style="overflow:auto;white-space:nowrap;width:100"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw3">echo</span> abcd123 <span class="sy0">|</span> <span class="kw2">sed</span> <span class="st_h">'s/\([a-z]*\).*/\U\1/'</span></div></div>
<p>The student reported the following output: &#8220;Uabcd&#8221;. (The expected output is &#8220;ABCD&#8221;, which is what I get on Linux)</p>
<p>I tried it, and it worked fine for me. Then I thought: maybe this is a Mac/Linux problem. Sure enough, when I look at the man page for my Fedora 7 box, it tells me that my version of sed is GNU 4.1.5, from June 2006. Mac Leopard (10.5) is using BSD sed from July 2004. Leopard came out in 2007, as did Fedora 7. Why is it 2 years behind? Why is it still using python 2.4? Why doesn&#8217;t it come with useful utilities like dos2unix? Mac has done a great job of making a nice GUI, with some pretty cool applications like iLife. It is falling behind when it comes to the command line utilities though. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.robfelty.com/2008/09/15/why-doesnt-mac-update-standard-unix-utilities/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Strange bracketing behavior in grep and sed</title>
		<link>http://blog.robfelty.com/2008/09/03/strange-bracketing-behavior-in-grep-and-sed/</link>
		<comments>http://blog.robfelty.com/2008/09/03/strange-bracketing-behavior-in-grep-and-sed/#comments</comments>
		<pubDate>Wed, 03 Sep 2008 16:58:48 +0000</pubDate>
		<dc:creator>robfelty</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[regular expressions]]></category>
		<category><![CDATA[sed]]></category>

		<guid isPermaLink="false">http://blog.robfelty.com/?p=115</guid>
		<description><![CDATA[I finally figured out this thorny issue I have been dealing with for the last hour. In perl, if I can create a character class like &#8220;[\[\]a-f]&#8221; which matches any characters a-f, [, and ]. This does not work in grep or sed though. I finally discovered that the right bracket &#8220;]&#8221; should not be [...]]]></description>
			<content:encoded><![CDATA[<p>I finally figured out this thorny issue I have been dealing with for the last hour. In perl, if I can create a character class like &#8220;[\[\]a-f]&#8221; which matches any characters a-f, [, and ]. This does not work in grep or sed though. I finally discovered that the right bracket &#8220;]&#8221; should not be escaped in grep or sed. I don&#8217;t really understand why. Perl will let you do it either way. </p>
<p>You know what they say: &#8220;knowing is half the battle.&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.robfelty.com/2008/09/03/strange-bracketing-behavior-in-grep-and-sed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bash one-liners to the rescue</title>
		<link>http://blog.robfelty.com/2008/07/15/bash-one-liners-to-the-rescue/</link>
		<comments>http://blog.robfelty.com/2008/07/15/bash-one-liners-to-the-rescue/#comments</comments>
		<pubDate>Tue, 15 Jul 2008 13:52:14 +0000</pubDate>
		<dc:creator>robfelty</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[linguistics]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[sox]]></category>
		<category><![CDATA[wav]]></category>

		<guid isPermaLink="false">http://blog.robfelty.com/?p=103</guid>
		<description><![CDATA[I recently find myself using handy bash one-liners more all the time. I think that this is where unix/linux can really start to shine. There are so many little programs that just do one thing, and one thing well. But the ability to combine these together through pipes means you have extremely flexible and powerful [...]]]></description>
			<content:encoded><![CDATA[<p>I recently find myself using handy bash one-liners more all the time. I think that this is where unix/linux can really start to shine. There are so many little programs that just do one thing, and one thing well. But the ability to combine these together through pipes means you have extremely flexible and powerful tools at the ready. </p>
<p>I have been working on a new project at work to come up with some lists for testing speech recognition. We decided to use the TIMIT database, which contains recordings of many different sentences from many different speakers all around America. I first wrote a perl script to generate some basic stats on the sentences, like how many words were in each sentence, and what the word frequency for those words is. Then I wrote a perl script to randomly select some of the sentences, and create several different lists of sentences. Finally, I wrote an R script which took the original .wav files, and mixed in signal-dependent noise in one channel, so that we can vary the signal to noise ratio during presentation of the stimuli by adjusting the balance on our sound system. </p>
<p>Along the way, I ran into a couple problems with the original sound files. It turns out that 446 of the 6300 sound files were clipped, and highly distorted. I noticed this on my own in listening to a few of the files I had generated with R. I could have gone through all 6300 files manually, and removed the distorted ones, but that would have taken a long time. Instead,  I used the program <em>sox</em>, which is a low-level, powerful audio processing program. I first used the find command to find all .wav files in the directory I was interested in (including sub-directories), then I passed each file to sox, and told sox not to play the output , but instead just give me some stats (-n stat). After some testing with a few clipped, and non-clipped files, I realized that for clipped files, the output from sox ended with a line that said either &#8220;Try: blah blah&#8221;, or &#8220;Can&#8217;t determine type&#8221;. I then later discovered that there might still be clipped files, and these would have a maximum amplitude of 1 or minimum or -1. So I knew that any clipped file would produce this output. So I passed the results from sox to grep (notice I had to redirect STDERR to STDOUT 2>&#038;1), and then if the output contained a line starting with  &#8220;Try:&#8221;  or &#8220;Can&#8217;t&#8221;, then I moved that file the $file.clipped.</p>
<div class="codecolorer-container bash dawn" style="overflow:auto;white-space:nowrap;width:100"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">for</span> <span class="kw2">file</span> <span class="kw1">in</span> <span class="sy0">`</span><span class="kw2">find</span> . <span class="re5">-name</span> <span class="st0">&quot;*.wav&quot;</span> -print<span class="sy0">`</span>; <span class="kw1">do</span> <br />
&nbsp; <span class="kw1">if</span> <span class="br0">&#91;</span><span class="br0">&#91;</span> <span class="sy0">`</span><span class="kw2">sox</span> <span class="re1">$file</span> <span class="re5">-n</span> <span class="kw2">stat</span> <span class="nu0">2</span><span class="sy0">&gt;&amp;</span><span class="nu0">1</span> <span class="sy0">|</span> <span class="kw2">grep</span> <span class="re5">-E</span> <span class="st0">&quot;^(Try:|Can't|(Minimum|Maximum) amplitude:\s+-?1\.00)&quot;</span><span class="sy0">`</span> <span class="br0">&#93;</span><span class="br0">&#93;</span>; <span class="kw1">then</span><br />
&nbsp; &nbsp; <span class="kw3">echo</span> <span class="st0">&quot;<span class="es2">$file</span> CLIPPED&quot;</span>; <br />
&nbsp; &nbsp; <span class="kw2">mv</span> <span class="re1">$file</span> <span class="re1">$file</span>.clipped; <br />
&nbsp; <span class="kw1">fi</span>; <br />
<span class="kw1">done</span></div></div>
<p>After doing this, I simply amended my perl script which randomly generated lists to make sure that the wav file actually existed. Clipped files now ended in .clipped, instead of .wav.</p>
<p>There was an additional problem I had previously discovered with these sound files. They seemed to have some non-standard headers in them, which meant that the R script I was using to add noise to them couldn&#8217;t read the files. However, passing the files through sox made the files readable by R. (Windows Media Player on a Windows box couldn&#8217;t read the files either.) I only wanted to process the files I was actually going to add noise to, so I used another handy little bash one-liner. This one cuts a column of the file which contains all the sentences I am going to use, and then for each filename, processes the file through sox, and outputs it to the destination directory of my choosing.</p>
<div class="codecolorer-container bash dawn" style="overflow:auto;white-space:nowrap;width:100"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">for</span> <span class="kw2">file</span> <span class="kw1">in</span> <span class="sy0">`</span><span class="kw2">cut</span> <span class="re5">-f</span> <span class="nu0">18</span> <span class="re5">-d</span> $<span class="st_h">'\t'</span> timitLists2.txt<span class="sy0">`</span>; <br />
&nbsp; <span class="kw1">do</span> <span class="kw2">sox</span> <span class="re1">$file</span> ~<span class="sy0">/</span>R<span class="sy0">/</span>work<span class="sy0">/</span>timit<span class="sy0">/</span>clean<span class="sy0">/`</span><span class="kw2">basename</span> <span class="re1">$file</span><span class="sy0">`</span>; <br />
<span class="kw1">done</span></div></div>
<p>Note that I have expanded the code into one more line, but pretty much they are one-liners. I think technically a one-liner doesn&#8217;t involve successive commands, which the first example does, but the first command is just an echo, to make sure I know what it is doing. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.robfelty.com/2008/07/15/bash-one-liners-to-the-rescue/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>sort using TAB as field separator in bash</title>
		<link>http://blog.robfelty.com/2008/07/14/sort-using-tab-as-field-separator-in-bash/</link>
		<comments>http://blog.robfelty.com/2008/07/14/sort-using-tab-as-field-separator-in-bash/#comments</comments>
		<pubDate>Mon, 14 Jul 2008 14:28:44 +0000</pubDate>
		<dc:creator>robfelty</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[tab]]></category>

		<guid isPermaLink="false">http://blog.robfelty.com/?p=102</guid>
		<description><![CDATA[I have run into this problem several times recently, and decided to finally write down the solution for myself rather than keep searching the internet for it. This is the problem: if you want to sort a file that is tab-delimited (and some of the filelds contain spaces), then you must explicitly tell sort to [...]]]></description>
			<content:encoded><![CDATA[<p>I have run into this problem several times recently, and decided to finally write down the solution for myself rather than keep searching the internet for it. </p>
<p>This is the problem: if you want to sort a file that is tab-delimited (and some of the filelds contain spaces), then you must explicitly tell sort to use TABS as the field separator, otherwise it will use any whitespace character. For functions such as cut and paste, this can be done like so:</p>
<div class="codecolorer-container bash dawn" style="overflow:auto;white-space:nowrap;width:100"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw2">cut</span> <span class="re5">-f</span> <span class="nu0">1</span> <span class="re5">-d</span> <span class="st_h">'\t'</span> <span class="kw2">file</span></div></div>
<p>where -f specifies the field number and -d specifies the field seperator.<br />
The sort command uses the -t flag instead. So one would think that this would work:</p>
<div class="codecolorer-container bash dawn" style="overflow:auto;white-space:nowrap;width:100"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="co0">#INCORRECT</span><br />
<span class="kw2">sort</span> <span class="re5">-k</span> <span class="nu0">2</span> <span class="re5">-t</span> <span class="st_h">'\t'</span> <span class="kw2">file</span></div></div>
<p>where -k specifies the field number and -t specifies the field separator<br />
Unfortunately this does not work, because sort won&#8217;t accept &#8216;\t&#8217;, since it treats it as a multi-byte character. The solution is to place a $ before it, like so:</p>
<div class="codecolorer-container bash dawn" style="overflow:auto;white-space:nowrap;width:100"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="co0">#CORRECT</span><br />
<span class="kw2">sort</span> <span class="re5">-k</span> <span class="nu0">2</span> <span class="re5">-t</span> $<span class="st_h">'\t'</span> <span class="kw2">file</span></div></div>
<p>The dollar sign tells bash to use ANSI-C quoting<br />
From: <a href='http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_03.html'>http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_03.html</a></p>
<blockquote><p>
3.3.5. ANSI-C quoting</p>
<p>Words in the form &#8220;$&#8217;STRING&#8217;&#8221; are treated in a special way. The word expands to a string, with backslash-escaped characters replaced as specified by the ANSI-C standard. Backslash escape sequences can be found in the Bash documentation.
</p></blockquote>
<p>So now I have the answer for myself the next time the problem arises. I hope someone else benefits as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.robfelty.com/2008/07/14/sort-using-tab-as-field-separator-in-bash/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Xorg.conf configuration &#8212; solved font size problem</title>
		<link>http://blog.robfelty.com/2008/03/21/xorgconf-configuration-solved-font-size-problem/</link>
		<comments>http://blog.robfelty.com/2008/03/21/xorgconf-configuration-solved-font-size-problem/#comments</comments>
		<pubDate>Fri, 21 Mar 2008 21:12:33 +0000</pubDate>
		<dc:creator>robfelty</dc:creator>
				<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://blog.robfelty.com/2008/03/21/xorgconf-configuration-solved-font-size-problem/</guid>
		<description><![CDATA[Awhile ago I started having problems with some of my fonts on my computer at work. Interestingly enough, it only seemed to affect a very small minority of programs and situations, namely on startup, when Fedora is going through and telling me all the services it is starting, the fonts were so tiny I could [...]]]></description>
			<content:encoded><![CDATA[<p>Awhile ago I started having problems with some of my fonts on my computer at work. Interestingly enough, it only seemed to affect a very small minority of programs and situations, namely on startup, when Fedora is going through and telling me all the services it is starting, the fonts were so tiny I could not read them. This also seemed to be the case for Matlab. For Matlab, I temporarily solved the problem by just changing the settings to use really big fonts (like 30 point or so). But today I wanted to run EEGlab, which is a Matlab toolbox to analyze EEG data. The toolbox has a GUI, and the GUI fonts were also tiny. I decided I needed to dig around some more, and I finally fixed the problem. Ultimately it was a misconfiguration in my xorg.conf file, that mysterious file that can cause so many things to go wrong on Linux. I discovered that Fedora uses the /etc/X11/Xresources file to specify the DPI (dots per inch), that your screen should have. It was set at 96 dpi, which seemed correct. And it must be the case that most programs use this value when calculating how to display fonts. However, there is also an option in the Monitor section of xorg.conf called DisplaySize, which is some sort of combination of the display resolution and the DPI. More precisely, the display size should be &lt;pixelsize&gt;/96*25.4. For the 1440&#215;900 monitor I use at work, this turned out to be 381&#215;238. Previously I had it set to 1440 x 900, which was why my fonts were so tiny.<br />
To summarize, my xorg.conf looks like:</p>
<div class="codecolorer-container bash dawn" style="overflow:auto;white-space:nowrap;width:100;height:300px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="co0"># Xorg configuration created by system-config-display</span><br />
<br />
Section <span class="st0">&quot;ServerLayout&quot;</span><br />
&nbsp; &nbsp; Identifier &nbsp; &nbsp; <span class="st0">&quot;single head configuration&quot;</span><br />
&nbsp; &nbsp; Screen &nbsp; &nbsp; &nbsp;<span class="nu0">0</span> &nbsp;<span class="st0">&quot;Screen0&quot;</span> <span class="nu0">0</span> <span class="nu0">0</span><br />
&nbsp; &nbsp; InputDevice &nbsp; &nbsp;<span class="st0">&quot;Keyboard0&quot;</span> <span class="st0">&quot;CoreKeyboard&quot;</span><br />
EndSection<br />
<br />
Section <span class="st0">&quot;InputDevice&quot;</span><br />
&nbsp; &nbsp; Identifier &nbsp;<span class="st0">&quot;Keyboard0&quot;</span><br />
&nbsp; &nbsp; Driver &nbsp; &nbsp; &nbsp;<span class="st0">&quot;kbd&quot;</span><br />
&nbsp; &nbsp; Option&nbsp; &nbsp; &nbsp; <span class="st0">&quot;XkbModel&quot;</span> <span class="st0">&quot;pc105&quot;</span><br />
&nbsp; &nbsp; Option&nbsp; &nbsp; &nbsp; <span class="st0">&quot;XkbLayout&quot;</span> <span class="st0">&quot;us&quot;</span><br />
EndSection<br />
<br />
Section <span class="st0">&quot;Device&quot;</span><br />
&nbsp; &nbsp; Identifier &nbsp;<span class="st0">&quot;Videocard0&quot;</span><br />
&nbsp; &nbsp; Driver &nbsp; &nbsp; &nbsp;<span class="st0">&quot;radeon&quot;</span><br />
Option &nbsp; <span class="st0">&quot;UseEdidDpi&quot;</span> &nbsp; <span class="st0">&quot;FALSE&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Option &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;DPI&quot;</span> <span class="st0">&quot;100 x 100&quot;</span><br />
EndSection<br />
<br />
Section <span class="st0">&quot;Monitor&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Identifier &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&quot;Monitor0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; HorizSync &nbsp; &nbsp; &nbsp; <span class="nu0">30.0</span> - <span class="nu0">82.0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; VertRefresh &nbsp; &nbsp; <span class="nu0">50.0</span> - <span class="nu0">85.0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Option &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&quot;DPMS&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Modeline &nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&quot;1440x900_70.00&quot;</span> <span class="nu0">126.98</span> <span class="nu0">1440</span> <span class="nu0">1536</span> <span class="nu0">1688</span> <span class="nu0">1936</span> <span class="nu0">900</span> <span class="nu0">901</span> <span class="nu0">904</span> <span class="nu0">937</span> <span class="re5">-HSync</span> +Vsync<br />
&nbsp; &nbsp; &nbsp; &nbsp; Modeline &nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&quot;1440x900_60.00&quot;</span> <span class="nu0">106.47</span> <span class="nu0">1440</span> <span class="nu0">1520</span> <span class="nu0">1672</span> <span class="nu0">1904</span> <span class="nu0">900</span> <span class="nu0">901</span> <span class="nu0">904</span> <span class="nu0">932</span> <span class="re5">-HSync</span> +Vsync<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co0">#DisplaySize &nbsp; &nbsp; 1440 900</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; DisplaySize &nbsp; &nbsp; <span class="nu0">381</span> <span class="nu0">238</span><br />
EndSection<br />
<br />
Section <span class="st0">&quot;Screen&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Identifier &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&quot;Screen0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Device &nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&quot;VideoCard0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Monitor &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;Monitor0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; DefaultDepth &nbsp; &nbsp;<span class="nu0">24</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;SubSection &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&quot;Display&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Depth &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="nu0">24</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Modes &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;1440x900_70.00&quot;</span> <span class="st0">&quot;1440x900_60.00&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; EndSubSection<br />
EndSection</div></div>
<p>Now I am very happy about my working fonts!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.robfelty.com/2008/03/21/xorgconf-configuration-solved-font-size-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>convert pdf to png with imagemagick</title>
		<link>http://blog.robfelty.com/2008/03/11/convert-pdf-to-png-with-imagemagick/</link>
		<comments>http://blog.robfelty.com/2008/03/11/convert-pdf-to-png-with-imagemagick/#comments</comments>
		<pubDate>Tue, 11 Mar 2008 21:13:32 +0000</pubDate>
		<dc:creator>robfelty</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[mac osx]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[image conversion]]></category>
		<category><![CDATA[imagemagick]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[png]]></category>

		<guid isPermaLink="false">http://blog.robfelty.com/2008/03/11/convert-pdf-to-png-with-imagemagick/</guid>
		<description><![CDATA[Imagemagick is a swiss-army knife of command-line image conversion, but can be a bit complicated to actually use. I have been making most of my figures with R lately, and printing them to pdfs, which I can include very easily into documents with pdflatex. I like pdf because it is scalable, fairly small file size [...]]]></description>
			<content:encoded><![CDATA[<p>Imagemagick is a swiss-army knife of command-line image conversion, but can be a bit complicated to actually use. I have been making most of my figures with R lately, and printing them to pdfs, which I can include very easily into documents with pdflatex. I like pdf because it is scalable, fairly small file size (smaller than .eps), and portable. But today a colleague wanted to include a few of my figures in her own powerpoint presentation, and powerpoint only likes bitmaps. She was just going to take screenshots of the figures, but I quickly said, &#8220;no, I will just convert them to pngs&#8221;. She replied: &#8220;I don&#8217;t want you to go to a bunch of trouble.&#8221; &#8220;No trouble at all,&#8221; I replied. Then I quickly wrote a bash for loop to convert all the pdf figures into pngs. Then an hour later  when I went to zip them up and e-mail them to her, I realized that they looked like crap. After a bit of searching online, I found the flags I was looking for, and eventually used:</p>
<div class="codecolorer-container bash dawn" style="overflow:auto;white-space:nowrap;width:100"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">for</span> <span class="kw2">file</span> <span class="kw1">in</span> <span class="sy0">*</span>.pdf; <span class="kw1">do</span> \<br />
<span class="kw3">echo</span> <span class="re1">$file</span>;\<br />
convert <span class="re5">-density</span> 600x600 <span class="re5">-resize</span> 800x560 <span class="re5">-quality</span> <span class="nu0">90</span> <span class="re1">$file</span> <span class="sy0">`</span><span class="kw3">echo</span> <span class="re1">$file</span><span class="sy0">|</span><span class="kw2">cut</span> <span class="re5">-f1</span> <span class="re5">-d</span><span class="st_h">'.'</span><span class="sy0">`</span>.png;\<br />
<span class="kw1">done</span></div></div>
<p>And now the code explained:<br />
-density 600&#215;600 says treat the pdf as 600&#215;600 dpi resolution<br />
-quality 90 says use the highest compression level for png (9) and no filtering (0)<br />
-resize 800&#215;560 gives the dimensions in pixels of the resulting png file</p>
<p>Happy ImageMagicking!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.robfelty.com/2008/03/11/convert-pdf-to-png-with-imagemagick/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>vi key bindings in R</title>
		<link>http://blog.robfelty.com/2007/11/28/vi-key-bindings-in-r/</link>
		<comments>http://blog.robfelty.com/2007/11/28/vi-key-bindings-in-r/#comments</comments>
		<pubDate>Wed, 28 Nov 2007 22:11:40 +0000</pubDate>
		<dc:creator>robfelty</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[key bindings]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[statistics]]></category>
		<category><![CDATA[vi]]></category>

		<guid isPermaLink="false">http://blog.robfelty.com/2007/11/28/vi-key-bindings-in-r/</guid>
		<description><![CDATA[I am working on learning R. For those that don&#8217;t know, R is a programming language and program a bit similar to Matlab, but is particularly designed for statistics. It is free and open source, and pretty fast and flexible. It has a pretty nice library interface, with lots of user contributed libraries at CRAN [...]]]></description>
			<content:encoded><![CDATA[<p>I am working on learning <a href='http://www.r-project.org/'>R</a>. For those that don&#8217;t know, R is a programming language and program a bit similar to Matlab, but is particularly designed for statistics. It is free and open source, and pretty fast and flexible. It has a pretty nice library interface, with lots of user contributed libraries at <a href='http://cran.r-project.org'>CRAN</a> (The comprehensive R archive network &#8212; modeled after CTAN and CPAN (Tex and Perl respectively)). </p>
<p>On *nix systems, R uses the readline library to give a command history. So I can simply type the up arrow, and find the last command I used. I just discovered that it can also search the command history in the same way as in my BASH shell. Since I like <em>vi</em>, I use <em>vi</em> key bindings in bash. I was pleasantly surprised when R automatically used these as well. I am not sure if it gets them from my .bashrc file or my .inputrc file, since I have vi keymaps set in both.<br />
.bashrc:</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;width:100"><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">set -o vi</div></div>
<p>.inputrc</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;width:100"><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">set editing-mode vi<br />
set keymap vi</div></div>
<p>So when I am using R, I can search the history for &#8220;foo&#8221; by typing:<br />
&lt;esc&gt; /foo</p>
<p>and then use &#8216;n&#8217; and &#8216;N&#8217; to go to the next or previous match.</p>
<p>What fun!!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.robfelty.com/2007/11/28/vi-key-bindings-in-r/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
