コマンドラインでperlを使う
たとえば、全ファイルからサブルーチン名を抜き出したいと思ったとき。
% grep sub * | perl -nle '/sub\s+(\w+)/ and print $1;'
こういうことばっかりやってると、perlが無い環境にいったときに苦労する。
そんな環境滅んでしまえって気もするが。
% grep sub * | sed -n 's/.*sub \([a-zA-Z0-9_]*\).*/\1/p'
sed
man sed
-n, --quiet, --silent
suppress automatic printing of pattern space
info sed
The `s' command can be followed by zero or more of the following FLAGS:
`p'
If the substitution was made, then print the new pattern space.Note: when both the `p' and `e' options are specified, the
relative ordering of the two produces very different results. In
general, `ep' (evaluate then print) is what you want, but
operating the other way round can be useful for debugging. For
this reason, the current version of GNU `sed' interprets specially
the presence of `p' options both before and after `e', printing
the pattern space before and after evaluation, while in general
flags for the `s' command show their effect just once. This
behavior, although documented, might change in future versions.
最初、manだけ見ててpをコマンドと勘違いした。