<?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>Otaqui.Com &#187; command-line</title>
	<atom:link href="http://otaqui.com/blog/tag/command-line/feed/" rel="self" type="application/rss+xml" />
	<link>http://otaqui.com/blog</link>
	<description>Pete Otaqui's blog about web development and everything else</description>
	<lastBuildDate>Wed, 23 Jun 2010 09:55:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Bash Script for Serving Multiple Trac Projects and Sharing Authentication</title>
		<link>http://otaqui.com/blog/600/bash-script-for-serving-multiple-trac-projects-and-sharing-authentication/</link>
		<comments>http://otaqui.com/blog/600/bash-script-for-serving-multiple-trac-projects-and-sharing-authentication/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 08:55:25 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/?p=600</guid>
		<description><![CDATA[I use Trac for personal projects, and I share some of these out with people as required. I use tracd (TracStandalone) for this, rather than a full-blown apache setup, since it serves my needs quite nicely and is a lot easier to turn on and off as required without tweaking apache config and rebooting the [...]]]></description>
			<content:encoded><![CDATA[<p>I use Trac for personal projects, and I share some of these out with people as required.  I use tracd (TracStandalone) for this, rather than a full-blown apache setup, since it serves my needs quite nicely and is a lot easier to turn on and off as required without tweaking apache config and rebooting the whole webserver.</p>
<p>All my projects live under a single parent directory, and I prefer to share a single users digest file between them all &#8211; so ideally I wanted to share a single tracd to run all my projects.  This is fairly straightforward on the command line:</p>
<pre class="brush: bash">
tracd --hostname=webhost.com -p 9876 \
--auth=&quot;*,/path/projects/people.htdigest,Realm&quot; \
/path/projects/p1 \
/path/projects/p2
</pre>
<p>That is &#8230;.<br />
Line 1 &#8211; start tracd for a given hostname and port,<br />
Line 2 &#8211; specify auth for all projects (*), the auth file and the &#8220;Realm&#8221; you specified when creating the file with apache&#8217;s htdigest command<br />
Lines 3+ &#8211; specify as many projects as you want to run</p>
<p>This is ok with a couple of projects, but gets unwieldy quite quickly.  What I needed was a little shell script to open up all projects under a given directory quickly.  Here&#8217;s what I came up with:</p>
<pre class="brush: bash">
#!/bin/bash

# make / truncate a temp file to store names:
temp=/tmp/tracdpaths
&gt; $temp

# specify base directory:
base=/path/projects/

# output all subdirectories to temp file:
find $base -maxdepth 1 -mindepth 1 -type d \
-exec echo -n &quot;{} &quot; &gt; $temp \;

# now start tracd
tracd --hostname=webhost.com -p 9876 \
--auth=&quot;*,/path/projects/people.htdigest,Realm&quot; \
`cat $temp`
</pre>
<p>Essentially this script uses &#8216;find&#8217; to get all of the directories exactly 1 level down from your projects directory, and will echo their paths to a temp file (suppressing the newlines).  It will then run run tracd, appending the contents of this file to the end of the call.</p>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/600/bash-script-for-serving-multiple-trac-projects-and-sharing-authentication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Comment And Uncomment All Lines in a Linux File with Sed</title>
		<link>http://otaqui.com/blog/460/comment-and-uncomment-all-lines-in-a-linux-file-with-sed/</link>
		<comments>http://otaqui.com/blog/460/comment-and-uncomment-all-lines-in-a-linux-file-with-sed/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 09:21:27 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[mac]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/?p=460</guid>
		<description><![CDATA[Just a couple of sed one-liners for adding and removing comments in the form of # marks (in the case of my ~/.ssh/config file). I use this to toggle proxy settings (with connect.c) and it&#8217;s run by the awesome MarcoPolo location-aware app for OS X. Both of these are safe to run repeatedly (you won&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Just a couple of sed one-liners for adding and removing comments in the form of # marks (in the case of my ~/.ssh/config file).  I use this to toggle proxy settings (with connect.c) and it&#8217;s run by the awesome MarcoPolo location-aware app for OS X.  Both of these are safe to run repeatedly (you won&#8217;t end up with multiple # marks or anything).</p>
<p>First adding comments, which means a &#8220;#&#8221; mark at the start of every line<br />
<code>sed -i '' 's/^\([^#]\)/#\1/g' ~/.ssh/config</code></p>
<p>Second removing the comments, just stripping out the &#8220;#&#8221; marks.<br />
<code>sed -i '' 's/^#//g' ~/.ssh/config</code></p>
<p>A few things to note here, on the assumption that you can see how Regular Expressions work and are vaguely familiar with sed&#8217;s /find/replace/ style syntax:</p>
<ol>
<li>the &#8220;-i&#8221; flag means &#8220;edit in place&#8221; and requires an extra argument for the backup file&#8217;s extension.  I&#8217;ve given an empty string so that no backup is made</li>
<li>sed requires escaping of capturing parentheses, hence the \( and \) in the first example</li>
<li>the final &#8216;g&#8217; at the end of the expressions means &#8220;global&#8221;, i.e. replace all occurences</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/460/comment-and-uncomment-all-lines-in-a-linux-file-with-sed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cucumber with Webrat and Mechanize on CentOS 5</title>
		<link>http://otaqui.com/blog/449/cucumber-with-webrat-and-mechanize-on-centos-5/</link>
		<comments>http://otaqui.com/blog/449/cucumber-with-webrat-and-mechanize-on-centos-5/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 13:55:38 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/?p=449</guid>
		<description><![CDATA[Thanks to Chris for this one. The trick is to use JRuby and its gems, and also to install libxml2-devel $ cd ~ $ wget http://jruby.kenai.com/downloads/1.4.0/jruby-bin-1.4.0.tar.gz $ tar -C /usr/local/ -xzvf jruby-bin-1.4.0.tar.gz You should now have Jruby. Add it&#8217;s bin directory to your path, presumably in your ~/.bash_profile file: $ export PATH=$PATH:/usr/local/jruby-1.4.0/bin $ jruby -v [...]]]></description>
			<content:encoded><![CDATA[<p>Thanks to <a href="http://blog.chrislowis.co.uk/">Chris</a> for this one.</p>
<p>The trick is to use JRuby and its gems, and also to install libxml2-devel</p>
<p><code>$ cd ~<br />
$ wget http://jruby.kenai.com/downloads/1.4.0/jruby-bin-1.4.0.tar.gz<br />
$ tar -C /usr/local/ -xzvf jruby-bin-1.4.0.tar.gz</code></p>
<p>You should now have Jruby.  Add it&#8217;s bin directory to your path, presumably in your ~/.bash_profile file:<br />
<code>$ export PATH=$PATH:/usr/local/jruby-1.4.0/bin<br />
$ jruby -v</code></p>
<p>Now install some mechanize requirements:<br />
<code>$ sudo yum install libxml2-devel libxslt-devel</code></p>
<p>If you <strong>don&#8217;t</strong> already have the &#8220;normal&#8221; ruby installed, you can get to the jruby &#8220;gem&#8221; command by just typing &#8220;gem&#8221;.  If you do have ruby, or want to be absolutely sure, type the commands like this:<br />
<code>$ jruby -S gem install cucumber mechanize webrat</code></p>
<p>You&#8217;re good to go!  You should now be able to run your features with:</p>
<p><code>$ cucumber features/</code></p>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/449/cucumber-with-webrat-and-mechanize-on-centos-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Listing files with the path in Bash</title>
		<link>http://otaqui.com/blog/88/listing-files-with-the-path-in-bash/</link>
		<comments>http://otaqui.com/blog/88/listing-files-with-the-path-in-bash/#comments</comments>
		<pubDate>Fri, 29 Feb 2008 21:43:54 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[mac]]></category>

		<guid isPermaLink="false">http://otaqui.com/wp/2008/03/listing-files-with-the-path-in-bash/</guid>
		<description><![CDATA[This little script will print a list of the current files in a directory, prefixed with the full path: #!/bin/sh curdir=`pwd` if [ $# -eq 1 ] then usrdir="$1" ls &#124; xargs -I % echo `pwd`/% &#124; sed -e s!$usrdir!! else ls &#124; xargs -I % echo `pwd`/% fi You can optionally provide an initial [...]]]></description>
			<content:encoded><![CDATA[<p>This little script will print a list of the current files in a directory, prefixed with the full path:</p>
<p><code>#!/bin/sh<br />
curdir=`pwd`<br />
if [ $# -eq 1 ]<br />
then<br />
	usrdir="$1"<br />
	ls | xargs -I % echo `pwd`/% | sed -e s!$usrdir!!<br />
else<br />
	ls | xargs -I % echo `pwd`/%<br />
fi</code></p>
<p>You can optionally provide an initial part of the path to ignore.  I use this when writing code change emails where I have to list the updated files within a codebase (and I&#8217;ve touched most files in a given directory) and I clip the local path up to the root of the codeset.  Assuming the script is saved as &#8220;lspath&#8221;:</p>
<p><code>lspath /Users/pete/Sites/project/trunk</code></p>
<p>Even handier is piping it into the OS X clipboard for easy pasting:</p>
<p><code>lspath /Users/pete/Sites/project/trunk | pbcopy</code></p>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/88/listing-files-with-the-path-in-bash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Split and Rename text files from the Bash command line</title>
		<link>http://otaqui.com/blog/85/split-and-rename-files-from-the-bash-command-line/</link>
		<comments>http://otaqui.com/blog/85/split-and-rename-files-from-the-bash-command-line/#comments</comments>
		<pubDate>Tue, 26 Feb 2008 15:17:30 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[mac]]></category>

		<guid isPermaLink="false">http://otaqui.com/wp/2008/02/split-and-rename-files-from-the-bash-command-line/</guid>
		<description><![CDATA[I occasionally read text files (usually downloaded from the Gutenberg Project) on my mobile phone. This is not the best user experience, but bearable and very useful at times. The most annoying issue is the incredibly slow management of very large text files (sometimes greater than 1Mb) that my phone displays &#8211; so i decided [...]]]></description>
			<content:encoded><![CDATA[<p>I occasionally read text files (usually downloaded from <a href="http://www.gutenberg.org/wiki/Main_Page">the Gutenberg Project</a>)  on my mobile phone.  This is not the best user experience, but bearable and very useful at times.</p>
<p>The most annoying issue is the incredibly slow management of very large text files (sometimes greater than 1Mb) that my phone displays &#8211; so i decided to rename them.</p>
<p>Using my mac, I came up with this couple of commands to do the work for me, between them they will split all text files into 1000 line chunks, and assuming an original filename of &#8220;somefile.txt&#8221; also rename them to &#8220;somefile_XX.txt&#8221; where XX is actually two letters denoting the part, starting at aa, ab, ac, etc.</p>
<p>The first command is dead easy and splits the files:</p>
<p><code> for file in *.txt ; do split $file $file ; done</code></p>
<p>This will split the files and turn &#8220;somefile.txt&#8221; into &#8220;somefile.txtaa&#8221;, &#8220;somefile.txtab&#8221;, &#8220;somefile.txtac&#8221; etc.  which is obviously not great &#8211; so we need the next step:</p>
<p><code>for file in * ; do mv $file `echo $file |<br />
sed 's/(.*).txt([a-z]{2})/1_2.txt/'` ; done</code></p>
<p>Now you should have all the files nicely named &#8220;somefile_aa.txt&#8221;, &#8220;somefile_ab.txt&#8221;, &#8220;somefile_ac.txt&#8221; etc.</p>
<p>You might prefer numbers rather than letters, in which case just check out the man page for the &#8216;split&#8217; command.</p>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/85/split-and-rename-files-from-the-bash-command-line/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
