<?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>The DF Lab &#187; bash</title>
	<atom:link href="http://blog.danfego.net/tag/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.danfego.net</link>
	<description>A guy like me?</description>
	<lastBuildDate>Tue, 03 Nov 2009 15:31:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Merging files with pr</title>
		<link>http://blog.danfego.net/2009/04/merging-files-with-pr/</link>
		<comments>http://blog.danfego.net/2009/04/merging-files-with-pr/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 09:00:18 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cli]]></category>

		<guid isPermaLink="false">http://blog.danfego.net/?p=212</guid>
		<description><![CDATA[Tonight, I&#8217;ve been poring over a rather large data set that I want to get some useful information out of. All the data was originally stored in a .html file, but after some (very) crude extraction techniques, I managed to pull out just the data I wanted, and shove it into a comma-separated file. Earlier, [...]]]></description>
			<content:encoded><![CDATA[<p>Tonight, I&#8217;ve been poring over a rather large data set that I want to get some useful information out of. All the data was originally stored in a .html file, but after some (very) crude extraction techniques, I managed to pull out just the data I wanted, and shove it into a comma-separated file. Earlier, I had given up on my tools at hand and typed up an entire list of row headings for my newly-gotten data. So I had two files like so:</p>
<p><code>headings.txt<br />
Alpha<br />
Bravo<br />
Charlie</code></p>
<p><code>values.csv<br />
1,2,3,4<br />
5,6,7,8<br />
9,10,11,12</code></p>
<p>I spent quite a bit of time trying to figure out how to combine the two columns into one file with what I knew, but none of my tools could quite do it without nasty shell scripting. It took me a while, but I eventually found <a href="http://www.unix.com/shell-programming-scripting/22481-column-merge.html#post87560">this post</a> that cracked the case for me. The <code>pr</code> command, ostensibly for paging documents, has enough horsepower to solve my problem in short order, like so:</p>
<p><code>$ pr -tm -s, headings.txt values.csv</code></p>
<p>The <code>-t</code> tells the program to omit headers and footers, and <code>-m</code> tells it to merge each line. The <code>-s,</code> tells it to use commas as field-separators. My desired result, like so:</p>
<p><code><code>headings.txt<br />
Alpha,1,2,3,4<br />
Bravo,5,6,7,8<br />
Charlie,9,10,11,12</code></p>
<p>There are numerous other options to <code>pr</code>, and depending on your potential line lengths, one may have to experiment. But for me, this got the job done.</p>
<p><strong>External Links</strong></p>
<ul>
<li><a href="http://www.unix.com/shell-programming-scripting/22481-column-merge.html#post87560">Where I discovered pr</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.danfego.net/2009/04/merging-files-with-pr/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Music Syncing Issues</title>
		<link>http://blog.danfego.net/2008/10/music-syncing-issues/</link>
		<comments>http://blog.danfego.net/2008/10/music-syncing-issues/#comments</comments>
		<pubDate>Mon, 06 Oct 2008 03:37:28 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[music]]></category>

		<guid isPermaLink="false">http://dlflab.wordpress.com/?p=14</guid>
		<description><![CDATA[I can sum up most of my computer-related decisions over the last 3 years or so as all being related to dealing with my hardware as best as possible.  This first led me to ditch Windows XP and try out Linux (Ubuntu first).  Then I tried fluxbox because GNOME was too heavy.  [...]]]></description>
			<content:encoded><![CDATA[<p>I can sum up most of my computer-related decisions over the last 3 years or so as all being related to dealing with my hardware as best as possible.  This first led me to ditch Windows XP and try out Linux (Ubuntu first).  Then I tried fluxbox because GNOME was too heavy.  Then I decided that Ubuntu didn&#8217;t deal all too well with switching out your desktop environment for a window manager, so I naively tried out this distribution I&#8217;ve come to know and love called Gentoo.  Now that I&#8217;m with Gentoo/fluxbox combo, I&#8217;ve managed, over time, to slim down my machine to just what I want, and have a pretty lean box, IMHO.  Not the leanest, but I did want a functional and pretty box as well. <img src='http://blog.danfego.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Anyway, this all correlates to a recent issue I&#8217;ve had with my music accounting system, and how I got around it with some frenzied bash scripting.  Because I&#8217;ve got a 4GB iPod Nano, I eventually came into the position of having too much music to fit on the device.  So I looked at my music and thought about compression.  Unfortunately, I couldn&#8217;t glean nearly enough space from that.  Then I realized that I <em>have</em> way more music than I actually listen to, so why not keep some music for computer listening, and some for mobile?  Well that&#8217;s a fantastic idea, but implementation gets a bit sticky.  I can try some convoluted system in which I keep a file of the unwanted files, update that manually, and&#8230; yeah, not too pretty.  Although I can&#8217;t quite say my solution was much prettier.</p>
<p>My current system involves a ~/music directory, and a ~/music-all directory.  My intention is to delete nothing from ~/music-all, ever.  ~/music contains music I actually want to listen to, and ~/music-ipod will contain music that I like enough to carry in my 4GB of space.  The key is that all the files within these three directories are hard links, so I&#8217;m not actually increasing my disk usage very much, and operations on the sets of files are much faster than if I had more than one copy of my files.  So assuming I hard link everything in ~/music-all to ~/music, I can then delete things from music at will, without losing it from my drive, but getting rid of it from listening.</p>
<p>With a schema in mind, then there&#8217;s the question of how to keep it up to date.  There are times when I want to add music to my collection, but then what do I do?  I could manually link the new files over, but&#8230; well, in retrospect, perhaps that would have been simpler.  But I decided I needed a script which would note the differences, relink ~/music-all to ~/music, then remove the files that I noted earlier (which were saved in a text file).  The benefit of all my toil was that it now makes my updates lightning fast and not tedious in the least.  I had to come up with two scripts, however: one to be run prior to changes to ~/music-all, and one once they&#8217;re made.  Below are the scripts, which probably won&#8217;t be of much use to anyone else, but they can essentially be used to keep two directories in sync, but with certain persistent changes.</p>
<p><a href="https://dl.getdropbox.com/u/221130/mtree-1">mtree-1</a><br />
<a href="https://dl.getdropbox.com/u/221130/mtree-2">mtree-2</a></p>
<p>Wow, I just spent <strong>way</strong> too much time figuring out how to post code here, and I&#8217;m still not satisfied with the result, so I ditched it.  The built-in &lt;code&gt; tag doesn&#8217;t seem to take to multiple lines all that well&#8230;  If anyone knows how to do that, do let me know!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.danfego.net/2008/10/music-syncing-issues/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cron, Backgrounds, and Fluxbox</title>
		<link>http://blog.danfego.net/2008/10/cron-backgrounds-and-fluxbox/</link>
		<comments>http://blog.danfego.net/2008/10/cron-backgrounds-and-fluxbox/#comments</comments>
		<pubDate>Sat, 04 Oct 2008 09:59:47 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[fluxbox]]></category>
		<category><![CDATA[gentoo]]></category>

		<guid isPermaLink="false">http://dlflab.wordpress.com/?p=8</guid>
		<description><![CDATA[Honest to God, I spent so much time getting this blog, domain, etc. up, that I almost forgot what spurred me to get started. So here&#8217;s why&#8230; I had this problem. Rather, not so much a problem as a desire to rotate my backgrounds periodically. Let&#8217;s say&#8230; every 2 hours. Now, a guy like me, [...]]]></description>
			<content:encoded><![CDATA[<p>Honest to God, I spent so much time getting this blog, domain, etc. up, that I almost forgot what spurred me to get started. So here&#8217;s why&#8230; I had this problem. Rather, not so much a problem as a desire to rotate my backgrounds periodically. Let&#8217;s say&#8230; every 2 hours. Now, a guy like me, I think &#8220;cron!&#8221; This is the first thought of any veteran Linux user. However, I quickly came to the realization that I didn&#8217;t know quite how or where to put my cron entries, nor what format. This problem was, however, quickly remedied. That was not my problem.</p>
<p>The true problem arose when I attempted to actually implement changing my background. With fluxbox, this should be possible with a simple command like so:</p>
<p><code>fbsetbg -a -r /home/dfego/.fluxbox/backgrounds/</code></p>
<p>Simple enough, right? Well, as simple as it was, it just didn&#8217;t quite work. So I changed my cron timings, in case I got that wrong then used absolute paths, once again, just in case. Freaked out for a while, because the command itself works just fine. I ran it from a terminal about 29,834 times to make sure, but still, that little cron daemon that could just wouldn&#8217;t budge. It <em>would</em>, however, write the text &#8220;working&#8221; into ~/cronf*cker every minute. As a matter of fact, it still is. Allow me to go take care of that&#8230;</p>
<p>Now that that&#8217;s taken care of, I&#8217;ll go ahead and tell you what the real problem was. Apparently the cron daemon doesn&#8217;t have any inherent knowledge of the X display server I want to set the background of. Fair enough, since it starts running well before X gets started. But I didn&#8217;t realize this would matter, or even think about it at all until I saw a post online about setting fluxbox backgrounds in a more general sense. It proposed butting DISPLAY=:0.0 before the line, like so:</p>
<p><code>DISPLAY=:0.0 fbsetbg -a -r /home/dfego/.fluxbox/backgrounds/</code></p>
<p>I changed the file, bit my lip, and a second or so after the next minute passed, my background was changed anew! As a note, my X server is not using display :0.0, but rather :1.0. You can find out what your value is by opening up a terminal and typing:</p>
<p><code>echo $DISPLAY</code></p>
<p>Anyway, there you have it. My first pearl of wisdom to the world! Apologies for verbosity, but sometimes in explanations such as this, it helps. So the moral of the story/digest version: <strong>be aware of context when running commands for X!</strong> Or something like that. I actually was at work today trying to impress a co-worker of mine with the power of the command line, but unfortunately my attempt fell flat on its face when passing commands to xmessage. I&#8217;m not too worried about it though. My ping/grep antics seemed to be enough to win him over.</p>
<p>With that, I&#8217;m off to bed, and to watch my background change once more before daybreak!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.danfego.net/2008/10/cron-backgrounds-and-fluxbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
