<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Batch Renaming Using sed</title>
	<atom:link href="http://www.guyrutenberg.com/2009/01/12/batch-renaming-using-sed/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.guyrutenberg.com/2009/01/12/batch-renaming-using-sed/</link>
	<description>Keeping track of what I do</description>
	<lastBuildDate>Tue, 07 Feb 2012 23:33:30 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Guy</title>
		<link>http://www.guyrutenberg.com/2009/01/12/batch-renaming-using-sed/comment-page-1/#comment-159431</link>
		<dc:creator>Guy</dc:creator>
		<pubDate>Fri, 13 Jan 2012 13:57:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=229#comment-159431</guid>
		<description>Coming back to the issue, I&#039;m feeling python is more suitable. A bit longer but safer (no shell escaping problems).

&lt;pre lang=&quot;python&quot;&gt;
import os
import re

[os.rename(s,re.sub(r&quot;(\d{4})(\d{2})&quot;,r&quot;\1-\2&quot;,s)) for s in os.listdir(&#039;.&#039;)]
&lt;/pre&gt;
The example above separates year-month dates using a dash (201201 -&gt; 2012-01).</description>
		<content:encoded><![CDATA[<p>Coming back to the issue, I&#8217;m feeling python is more suitable. A bit longer but safer (no shell escaping problems).</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
&nbsp;
<span style="color: black;">&#91;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">rename</span><span style="color: black;">&#40;</span>s,<span style="color: #dc143c;">re</span>.<span style="color: black;">sub</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;(<span style="color: #000099; font-weight: bold;">\d</span>{4})(<span style="color: #000099; font-weight: bold;">\d</span>{2})&quot;</span>,r<span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\1</span>-<span style="color: #000099; font-weight: bold;">\2</span>&quot;</span>,s<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> s <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">listdir</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'.'</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span></pre></div></div>

<p>The example above separates year-month dates using a dash (201201 -> 2012-01).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Guy</title>
		<link>http://www.guyrutenberg.com/2009/01/12/batch-renaming-using-sed/comment-page-1/#comment-91590</link>
		<dc:creator>Guy</dc:creator>
		<pubDate>Fri, 15 Jul 2011 05:05:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=229#comment-91590</guid>
		<description>&lt;code&gt;sed&lt;/code&gt; is indeed a unix command, so it doesn&#039;t exist natively in Windows. You can always intall something like cygwin which gives you a unix environment inside your windows. Also I&#039;m pretty sure that searching for &quot;sed for windows&quot; would turn up useful results.</description>
		<content:encoded><![CDATA[<p><code>sed</code> is indeed a unix command, so it doesn&#8217;t exist natively in Windows. You can always intall something like cygwin which gives you a unix environment inside your windows. Also I&#8217;m pretty sure that searching for &#8220;sed for windows&#8221; would turn up useful results.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: BatchNoob</title>
		<link>http://www.guyrutenberg.com/2009/01/12/batch-renaming-using-sed/comment-page-1/#comment-90743</link>
		<dc:creator>BatchNoob</dc:creator>
		<pubDate>Mon, 11 Jul 2011 08:06:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=229#comment-90743</guid>
		<description>Hello Guy, thank you for you answer.

No I haven&#039;t. I larked around with &quot;FOR /F&quot; until I read about sed on the web. Then you found your blog.
But I am not sure anymore, if sed is helping me further, since I am on Windows...

I understood, that sed is a Unix specific command. Is this correct? Do you know of an equivalent on Windows?

Thanks again!</description>
		<content:encoded><![CDATA[<p>Hello Guy, thank you for you answer.</p>
<p>No I haven&#8217;t. I larked around with &#8220;FOR /F&#8221; until I read about sed on the web. Then you found your blog.<br />
But I am not sure anymore, if sed is helping me further, since I am on Windows&#8230;</p>
<p>I understood, that sed is a Unix specific command. Is this correct? Do you know of an equivalent on Windows?</p>
<p>Thanks again!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Guy</title>
		<link>http://www.guyrutenberg.com/2009/01/12/batch-renaming-using-sed/comment-page-1/#comment-90117</link>
		<dc:creator>Guy</dc:creator>
		<pubDate>Fri, 08 Jul 2011 10:53:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=229#comment-90117</guid>
		<description>Have you tried
&lt;code&gt;sed s/\&quot;\&quot;/\&quot;/&lt;/code&gt;
?</description>
		<content:encoded><![CDATA[<p>Have you tried<br />
<code>sed s/\"\"/\"/</code><br />
?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: BatchNoob</title>
		<link>http://www.guyrutenberg.com/2009/01/12/batch-renaming-using-sed/comment-page-1/#comment-89984</link>
		<dc:creator>BatchNoob</dc:creator>
		<pubDate>Thu, 07 Jul 2011 12:01:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=229#comment-89984</guid>
		<description>Hello Guy,

it seems the you have quite some batch file programming experience! :)

Is it possible to replace &quot;&quot; with &quot; using sed?
(double quote replaced with single qoute)
I like to turn &quot;&quot;path&quot;&quot; to &quot;path&quot;.

Or do you know a side with a documentation for sed?</description>
		<content:encoded><![CDATA[<p>Hello Guy,</p>
<p>it seems the you have quite some batch file programming experience! <img src='http://www.guyrutenberg.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Is it possible to replace &#8220;&#8221; with &#8221; using sed?<br />
(double quote replaced with single qoute)<br />
I like to turn &#8220;&#8221;path&#8221;" to &#8220;path&#8221;.</p>
<p>Or do you know a side with a documentation for sed?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Guy</title>
		<link>http://www.guyrutenberg.com/2009/01/12/batch-renaming-using-sed/comment-page-1/#comment-79592</link>
		<dc:creator>Guy</dc:creator>
		<pubDate>Sat, 21 May 2011 19:19:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=229#comment-79592</guid>
		<description>Done, I&#039;m glad it has been an inspiration. I&#039;m aware of awk&#039;s advantages over sed, but I just didn&#039;t find the time, yet, to learn it properly. Sed is much simpler.</description>
		<content:encoded><![CDATA[<p>Done, I&#8217;m glad it has been an inspiration. I&#8217;m aware of awk&#8217;s advantages over sed, but I just didn&#8217;t find the time, yet, to learn it properly. Sed is much simpler.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Neville</title>
		<link>http://www.guyrutenberg.com/2009/01/12/batch-renaming-using-sed/comment-page-1/#comment-77325</link>
		<dc:creator>Neville</dc:creator>
		<pubDate>Wed, 11 May 2011 16:56:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=229#comment-77325</guid>
		<description>oops - for &quot;increase&quot; read &#039;decrease&#039;.

Guy - perhaps you could edit this for me and format the code.</description>
		<content:encoded><![CDATA[<p>oops &#8211; for &#8220;increase&#8221; read &#8216;decrease&#8217;.</p>
<p>Guy &#8211; perhaps you could edit this for me and format the code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Neville</title>
		<link>http://www.guyrutenberg.com/2009/01/12/batch-renaming-using-sed/comment-page-1/#comment-77321</link>
		<dc:creator>Neville</dc:creator>
		<pubDate>Wed, 11 May 2011 16:50:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=229#comment-77321</guid>
		<description>Thanks Guy for the inspiration this page gave me.

I had no experience of sed or awk but quickly got a sed solution to almost solve my problem and then discovered that arithmetic is not easy with sed.

After much playing the following worked:
&lt;pre lang=&quot;text&quot;&gt;
cd /test; find . -name &quot;ts*&quot; &#124; awk -F, &#039;{ print &quot;mv *&quot;$3&quot;,&quot;$4&quot; &quot;$3 -1000&quot;-&quot;$4 -1000&quot;.png&quot; }&#039; &#124; sh
&lt;/pre&gt;
This changes the names of all files below /test which start with &#039;ts&#039;. My file names were 137 characters long and included many special characters. They ended with comma separated data which I wanted to retain and decrease by 1000. My solution separates the data with a hyphen and adds an extension. Whilst restricting &#039;find&#039; to files starting with &#039;ts&#039; is not necessary it ensures directory names are not included (unless they start with ts!) and prevents the modified names being modified again - these may not happen but I think this simple restriction is a wise precaution.</description>
		<content:encoded><![CDATA[<p>Thanks Guy for the inspiration this page gave me.</p>
<p>I had no experience of sed or awk but quickly got a sed solution to almost solve my problem and then discovered that arithmetic is not easy with sed.</p>
<p>After much playing the following worked:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">cd /test; find . -name &quot;ts*&quot; | awk -F, '{ print &quot;mv *&quot;$3&quot;,&quot;$4&quot; &quot;$3 -1000&quot;-&quot;$4 -1000&quot;.png&quot; }' | sh</pre></div></div>

<p>This changes the names of all files below /test which start with &#8216;ts&#8217;. My file names were 137 characters long and included many special characters. They ended with comma separated data which I wanted to retain and decrease by 1000. My solution separates the data with a hyphen and adds an extension. Whilst restricting &#8216;find&#8217; to files starting with &#8216;ts&#8217; is not necessary it ensures directory names are not included (unless they start with ts!) and prevents the modified names being modified again &#8211; these may not happen but I think this simple restriction is a wise precaution.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.273 seconds -->

