grep -P で perl の正規表現が使えるらしい
な、なんだ(ry ってことでタイトルの通り。知りませんでした。
ただ、grep の version が古いとやはり使えないようです。
現状で入っている grep の version が 2.5.1 だったため、新しく入れなおす必要があります。
既に homebrew の repository に入っているようなので、いじってみることに。
% grep -V #=> grep (BSD grep) 2.5.1-FreeBSD % brew install grep % ggrep -V #=> ggrep (GNU grep) 2.14 Copyright (C) 2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.
どうやらbrew で入った grep のコマンドは ggrep という名前みたいです。
他にも gfgrep(grep -F), gegrep(grep -E) が既にインストールされています。
実験
% ggrep -P "^[a-z]{7}" ./*.rb #=> ./abc.rb:require './tmp/b.rb' ./c.rb:require './a' ./c.rb:require 'tmp/b.rb' ./t.rb:require 'active_model' ./tf.rb:require 'fastercsv' ./tf.rb:require 'tf_idf' ./tf.rb:comments # Array ./tf.rb:comments = comments.map do |c| ./tf.rb:documents = {}.tap do |doc|
というわけで無事抽出できてますね。
いつか使うかもしれません。いつか....
document
Man page of GREP
http://linuxjm.sourceforge.jp/html/GNU_grep/man1/grep.1.html
↑極めて実験的と書かれていますね。
GNU Grep 2.14
http://www.gnu.org/software/grep/manual/grep.html