「perlノート」(2005/11/13 (日) 00:02:00) の最新版変更点
追加された行は緑色になります。
削除された行は赤色になります。
<p>ワンライナー</p>
<p>
Myワンライナー「タグジャンプできるGrepの形式で出力」</p>
<table style="WIDTH: 633px; HEIGHT: 48px" border="1">
<tbody>
<tr>
<td>perl -ne "$i++; if(/^#/){print "log_XXX.txt" ;printf("(%3d):" ,$i);print};"
log_XXX.txt > grep_.txt</td>
</tr>
</tbody>
</table>
<br>
<p>
log_XXX.txtを引数にする。(スクリプトの中身に残ってしまう、、、</p>
<p>
ワンライナーで指定した引数ファイルをスクリプト中に指定するのは、どうやるんだ??</p>
<p>perl -ne " ワンライナーの内容 "</p>
<p>perl -pe " "</p>
<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC" border=
"1">
<caption>
<b>リスト7:ランダムな値を使っての書き換え</b></caption>
<tbody>
<tr>
<td>
<pre>
<code># replace string XYZ with a random number less than 611 in these filesperl -i.bak -pe "s/XYZ/int rand(611)/e" f1 f2 f3</code>
</pre></td>
</tr>
</tbody>
</table>
<p>
これは、<code>XYZ</code>を611(この値は、任意に選択できる)未満の値に置き換えるフィルターです。<code>rand()</code>は、0から引数までの間のランダムな値を返してくる関数でした。</p>
<p>
置換のつどintrand(611)が評価されますので、<code>XYZ</code>は、毎回、<i>異なる</i>ランダム値に置き換えられることになります。</p>
<h2><a id="code8" name="code8"></a></h2>
<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC" border=
"1">
<caption><b>リスト8:ファイルの基本的な性質の開示</b></caption>
<tbody>
<tr>
<td>
<pre>
<code># 1. Run basename on contents of fileperl -pe "s@.*/@@gio" INDEX</code>
</pre>
<pre>
<code># 2. Run dirname on contents of fileperl -pe 's@^(.*/)[^/]+@$1<img height="12"
alt="" src="http://www-06.ibm.com/jp/developerworks/i/bs.gif" width=
"8">n@' INDEX</code>
</pre>
<pre>
<code># 3. Run basename on contents of fileperl -MFile::Basename -ne 'print basename $_' INDEX</code>
</pre>
<pre>
<code># </code><code>4. Run dirname on contents of fileperl -MFile::Basename -ne 'print dirname $_' INDEX</code>
</pre></td>
</tr>
</tbody>
</table>
<br>
<pre>
IBM <a href=
"http://www-06.ibm.com/jp/developerworks/linux/030523/j_l-p102.html"><span class="astitle">洗練されたPerl: </span>ワンライナー102</a> より。
</pre>
<hr>
<p>ここ 、 <a href=
"http://todayiswednesday.seesaa.net/article/8378586.html">perlの元ソースの呼び出しもと行数を表示</a></p>
<p>ワンライナー</p>
<p>
Myワンライナー「タグジャンプできるGrepの形式で出力」</p>
<table style="WIDTH: 633px; HEIGHT: 48px" border="1">
<tbody>
<tr>
<td>perl -ne "$i++; if(/^#/){print "log_XXX.txt" ;printf("(%3d):"
,$i);print};"log_XXX.txt > grep_.txt</td>
</tr>
</tbody>
</table>
<br>
<p>
log_XXX.txtを引数にする。(スクリプトの中身に残ってしまう、、、</p>
<p>
ワンライナーで指定した引数ファイルをスクリプト中に指定するのは、どうやるんだ??</p>
<hr>
<p>perl -ne " ワンライナーの内容 "</p>
<p>perl -pe " "</p>
<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC" border=
"1">
<caption>
<b>リスト7:ランダムな値を使っての書き換え</b></caption>
<tbody>
<tr>
<td>
<pre>
<code># replace string XYZ with a random number less than 611 in these filesperl -i.bak -pe "s/XYZ/int rand(611)/e" f1 f2 f3</code>
</pre></td>
</tr>
</tbody>
</table>
<p>
これは、<code>XYZ</code>を611(この値は、任意に選択できる)未満の値に置き換えるフィルターです。<code>rand()</code>は、0から引数までの間のランダムな値を返してくる関数でした。</p>
<p>
置換のつどintrand(611)が評価されますので、<code>XYZ</code>は、毎回、<i>異なる</i>ランダム値に置き換えられることになります。</p>
<h2><a id="code8" name="code8"></a></h2>
<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC" border=
"1">
<caption><b>リスト8:ファイルの基本的な性質の開示</b></caption>
<tbody>
<tr>
<td>
<pre>
<code># 1. Run basename on contents of fileperl -pe "s@.*/@@gio" INDEX</code>
</pre>
<pre>
<code># 2. Run dirname on contents of fileperl -pe 's@^(.*/)[^/]+@$1<img height="12"
alt="" src="http://www-06.ibm.com/jp/developerworks/i/bs.gif" width=
"8">n@' INDEX</code>
</pre>
<pre>
<code># 3. Run basename on contents of fileperl -MFile::Basename -ne 'print basename $_' INDEX</code>
</pre>
<pre>
<code># </code><code>4. Run dirname on contents of fileperl -MFile::Basename -ne 'print dirname $_' INDEX</code>
</pre></td>
</tr>
</tbody>
</table>
<br>
<pre>
IBM <a href=
"http://www-06.ibm.com/jp/developerworks/linux/030523/j_l-p102.html"><span class="astitle">洗練されたPerl: </span>ワンライナー102</a> より。
</pre>
<hr>
<p>ここ 、 <a href=
"http://todayiswednesday.seesaa.net/article/8378586.html">perlの元ソースの呼び出しもと行数を表示</a></p>
表示オプション
横に並べて表示:
変化行の前後のみ表示: