R.A. Epigonos et al.

マッチしたファイルの内から特定の文字列のある行を抜き出す

D:\>perl -e "@F=<*.html>; foreach(@F){open IN,$_; print \"----------$_\n\"; while(<IN>){print if(m/1/);}; close IN;}"
----------test.html
    4 spaces 1 space
                2 tabs  1 tab
----------test2.html
<h1>PerlTestBody</h1>
D:\>

例えばこの例では"1"という文字が含まれている行を抜き出しているんだな。m//の中身を特定の文字に変えればいいんだな。

D:\>perl -e "@F=<*.html>; foreach(@F){open IN,$_; print \"----------$_\n\"; while(<IN>){print if(m/.*/);}; close IN;}"
----------test.html
    4 spaces 1 space
                2 tabs  1 tab
----------test2.html
<html><head><title>PerlTest</title></head>
<body>
<h1>PerlTestBody</h1>
<hr><p>AllAboutPerlOneLiner,SearchOn<a href="http://www.google.com">Google</a>WithSomeWords.Google'sLogo<img href="http://www.google.com" alt="GoogleLogo">IsHere.</p>
<a href="http://www.google.com">Google</a>
</body>
</html>
D:\>

ソーシャルブックマーク

  1. はてなブックマーク
  2. Google Bookmarks
  3. del.icio.us

ChangeLog

  1. Posted: 2007-12-23T02:00:47+09:00
  2. Modified: 2007-12-23T04:58:21+09:00
  3. Generated: 2023-08-27T23:09:11+09:00