<?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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>plusHa &#187; rename</title>
	<atom:link href="http://plusha.com/tag/rename/feed/" rel="self" type="application/rss+xml" />
	<link>http://plusha.com</link>
	<description>in the light</description>
	<lastBuildDate>Sat, 31 Dec 2011 01:57:59 +0000</lastBuildDate>
	<language>ko</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='plusha.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>plusHa &#187; rename</title>
		<link>http://plusha.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://plusha.com/osd.xml" title="plusHa" />
	<atom:link rel='hub' href='http://plusha.com/?pushpress=hub'/>
		<item>
		<title>Iterative execution script</title>
		<link>http://plusha.com/2008/06/06/iterative-execution-script/</link>
		<comments>http://plusha.com/2008/06/06/iterative-execution-script/#comments</comments>
		<pubDate>Fri, 06 Jun 2008 00:42:20 +0000</pubDate>
		<dc:creator>plusha</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[rename]]></category>
		<category><![CDATA[Shellscript]]></category>

		<guid isPermaLink="false">http://plusha.wordpress.com/?p=19</guid>
		<description><![CDATA[리눅스에서 동일한 작업을 이름 끝에 숫자가 붙은 여러 파일에 대해 반복적으로 하고 싶을 때 사용할 수 있는 shell script입니다. #!/bin/bash # Iterative execution script for numbered files # http://plusha.com, 24 Mar 2007 # # Procedure: # 1. Modify variables - EXE, OPT, IN, OUT, NMIN, NMAX # 2. Modify NUM format # 3. Modify Input/Output [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=plusha.com&amp;blog=174108&amp;post=19&amp;subd=plusha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>리눅스에서 동일한 작업을 이름 끝에 숫자가 붙은 여러 파일에 대해 반복적으로 하고 싶을 때 사용할 수 있는 shell script입니다.</p>
<pre><tt><code><em><span style="color:#9a1900;">#!/bin/bash</span></em>
<em><span style="color:#9a1900;"># Iterative execution script for numbered files</span></em>
<em><span style="color:#9a1900;"># http://plusha.com, 24 Mar 2007</span></em>
<em><span style="color:#9a1900;">#</span></em>
<em><span style="color:#9a1900;"># Procedure:</span></em>
<em><span style="color:#9a1900;">#   1. Modify variables - EXE, OPT, IN, OUT, NMIN, NMAX</span></em>
<em><span style="color:#9a1900;">#   2. Modify NUM format</span></em>
<em><span style="color:#9a1900;">#   3. Modify Input/Output type</span></em>
<em><span style="color:#9a1900;">#   4. Run the script</span></em>
<em><span style="color:#9a1900;">### put no space after '='</span></em>

<span style="color:#009900;">EXE</span><span style="color:#990000;">=</span>transp      <em><span style="color:#9a1900;"># Execution file</span></em>
<span style="color:#009900;">OPT</span><span style="color:#990000;">=</span><span style="color:#ff0000;">'n1=381'</span>    <em><span style="color:#9a1900;"># Options</span></em>

<span style="color:#009900;">IN</span><span style="color:#990000;">=</span>seismogram<span style="color:#990000;">.</span>          <em><span style="color:#9a1900;"># basename of input files</span></em>
<span style="color:#009900;">OUT</span><span style="color:#990000;">=</span>trseismogram<span style="color:#990000;">.</span>       <em><span style="color:#9a1900;"># basename of output files</span></em>

<span style="color:#009900;">NMIN</span><span style="color:#990000;">=</span><span style="color:#993399;">11</span>         <em><span style="color:#9a1900;"># Minimum number</span></em>
<span style="color:#009900;">NMAX</span><span style="color:#990000;">=</span><span style="color:#993399;">391</span>        <em><span style="color:#9a1900;"># Maximum number</span></em>
<span style="color:#009900;">INC</span><span style="color:#990000;">=</span><span style="color:#993399;">10</span>          <em><span style="color:#9a1900;"># Number increment</span></em>

<strong><span style="color:#0000ff;">for</span></strong> <span style="color:#990000;">((</span> <span style="color:#009900;">i</span><span style="color:#990000;">=</span><span style="color:#009900;">$NMIN</span> <span style="color:#990000;">;</span> i<span style="color:#990000;">&lt;=</span> <span style="color:#009900;">$NMAX</span> <span style="color:#990000;">;</span> <span style="color:#009900;">i</span><span style="color:#990000;">=</span>i<span style="color:#990000;">+</span><span style="color:#009900;">$INC</span> <span style="color:#990000;">))</span>
<strong><span style="color:#0000ff;">do</span></strong>
<em><span style="color:#9a1900;">### NUM format</span></em>
<em><span style="color:#9a1900;">#  NUM=$( printf "%02d\n" $i )  # 01,10,...,99</span></em>
<span style="color:#009900;">NUM</span><span style="color:#990000;">=</span><span style="color:#009900;">$(</span> <strong><span style="color:#0000ff;">printf</span></strong> <span style="color:#ff0000;">"%03d</span><span style="color:#cc33cc;">\n</span><span style="color:#ff0000;">"</span> <span style="color:#009900;">$i</span> <span style="color:#990000;">)</span>  <em><span style="color:#9a1900;"># 001,010,...,999</span></em>
<em><span style="color:#9a1900;">#  NUM=$( printf "%04d\n" $i )  # 0001,0010,...,9999</span></em>
echo <span style="color:#009900;">$NUM</span>

<em><span style="color:#9a1900;">### Input/Output type</span></em>
<em><span style="color:#9a1900;">#  $EXE $OPT   $IN$NUM   $OUT$NUM</span></em>
<span style="color:#009900;">$EXE</span> <span style="color:#009900;">$OPT</span> <span style="color:#990000;">&lt;</span> <span style="color:#009900;">$IN$NUM</span> <span style="color:#990000;">&gt;</span> <span style="color:#009900;">$OUT$NUM</span>
<em><span style="color:#9a1900;">#  $EXE $OPT &lt; $IN$NUM</span></em>
<strong><span style="color:#0000ff;">done</span></strong>
</code></tt></pre>
<p>위의 내용을 그대로 실행하면 아래의 내용을 실행한 것과 같습니다.<br />
<code>transp n1=381 trseismogram.011<br />
transp n1=381 trseismogram.021<br />
...<br />
transp n1=381 trseismogram.391</code><br />
변수들을 바꿔서 다양하게 사용할 수 있겠죠. 만약 여러 파일들의 이름을 바꾸고 싶다면 어떻게 하면 될까요?<br />
실행 명령을 mv로 바꾸고 옵션을 비우고 Input/output type을 첫 번 째 것으로 바꾸면 되겠죠? 그러면<br />
<code>mv old.001 new.001<br />
mv old.002 new.002<br />
mv old.003 new.003<br />
...</code><br />
과 같이 실행할 수 있겠죠. 하지만, 더 좋은 방법이 있습니다. &#8216;rename&#8217; 명령을 사용하면 됩니다.<br />
<code>rename old new pattern</code><br />
을 실행하면 세번째 argument의 pattern(glob pattern)에 해당하는 파일들을 모두 찾아 old라는 문자열을 new라는 문자열로 바꿔줍니다. 위의 경우에는<br />
<code>rename old new old.*</code><br />
과 같이 실행할 수 있겠죠.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/plusha.wordpress.com/19/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/plusha.wordpress.com/19/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/plusha.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/plusha.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/plusha.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/plusha.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/plusha.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/plusha.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/plusha.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/plusha.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/plusha.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/plusha.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/plusha.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/plusha.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/plusha.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/plusha.wordpress.com/19/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=plusha.com&amp;blog=174108&amp;post=19&amp;subd=plusha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://plusha.com/2008/06/06/iterative-execution-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">plusha</media:title>
		</media:content>
	</item>
	</channel>
</rss>
