<?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>Jason R Briggs &#187; shell-scripting</title>
	<atom:link href="http://www.briggs.net.nz/log/tag/shell-scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.briggs.net.nz/log</link>
	<description>Techie stuff from the perspective of a Kiwi abroad</description>
	<lastBuildDate>Mon, 28 Jun 2010 06:45:23 +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>shellscripts: batch renaming</title>
		<link>http://www.briggs.net.nz/log/2007/02/26/shellscripts-batch-renaming/</link>
		<comments>http://www.briggs.net.nz/log/2007/02/26/shellscripts-batch-renaming/#comments</comments>
		<pubDate>Mon, 26 Feb 2007 16:10:51 +0000</pubDate>
		<dc:creator>jrbriggs</dc:creator>
				<category><![CDATA[technical]]></category>
		<category><![CDATA[shell-scripting]]></category>

		<guid isPermaLink="false">http://www.briggs.net.nz/log/2007/02/26/shellscripts-batch-renaming/</guid>
		<description><![CDATA[Every time I sit down to write a shell-script, I have to stop and think. I seem to have a mental black hole in my head; into which all useful shell information inevitably seems to fall. For example, I always forget whether a &#8220;do&#8221; or &#8220;loop&#8221; comes at the end of the for-loop line (answer: [...]]]></description>
			<content:encoded><![CDATA[<p>Every time I sit down to write a shell-script, I have to stop and think.  I seem to have a mental black hole in my head; into which all useful shell information inevitably seems to fall.</p>
<p>For example, I always forget whether a &#8220;do&#8221; or &#8220;loop&#8221; comes at the end of the for-loop line (answer: it&#8217;s &#8220;do&#8221;)</p>
<p>Therefore, from now on, I&#8217;m now going to note-down useful scripts as I write them, so next time I have a senile moment, I can look them up easily.</p>
<p>&#8211; snip &#8211;</p>
<p>The following script can be used to batch rename files &#8212; for example, I created a few hundred files with quotes in the name (don&#8217;t ask), so rather than recreate all the files, this script uses tr (translation) to remove quotes in the new filename:</p>
<pre>
<code>
for x in `ls *.xml*`
do
    export x2=`echo $x | tr -d ["]`
    mv $x $x2
done
</code>
</pre>
<p>(single line version):</p>
<pre>
<code>
for x in `ls *.xml*`; do export x2=`echo $x | tr -d ["]`; mv $x $x2; done
</code>
</pre>
<p>Note #1: it doesn&#8217;t take into account the fact that some files don&#8217;t have quotation marks, so those move statements cause an error (but doesn&#8217;t otherwise cause any problems).</p>
<p>Note #2: there&#8217;s probably a quicker and easier way to do this&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.briggs.net.nz/log/2007/02/26/shellscripts-batch-renaming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
