基本
参考:
grep 正規表現を利用したテキストのパターン抽出 | bioinformatics
Linux で使う正規表現についてまとめました | エンジニアの入り口
ドキュメント
参考:
使い方
参考:
grep / egrep / fgrep コマンドのすべて 具体例編 – Qiita
マッチした部分のみ出力する
参考:
Can grep show only words that match search pattern? – Stack Overflow
How to display part of matched pattern in grep? – Stack Overflow
Can grep output only specified groupings that match? – Unix & Linux Stack Exchange
キーワードを含む・含まない
参考:
bash で正規表現 ある文字列を含んである文字列を含まない – Qiita
空白文字
拡張正規表現で \s
は空白文字を表す。
$ echo ” hello” | grep -E “\s*hello”
参考:
エスケープ
参考:
grep でドル記号やバックスラッシュを検索する | rcmdnk’s blog
コマンドオプションとパラメータ・ファイル名の区切り
コマンドラインで --
以降はオプションとして認識されない。
$ grep -- "---" file.txt
参考:
How to grep ‘—‘ in Linux? grep: unrecognized option ‘—‘ – Stack Overflow
fgrep
固定のキーワードを検索する場合に、通常の grep
に比べて処理が高速。
参考:
grep / egrep と fgrep の違い | 技術メモ帳
fgrep コマンド | IBM Knowledge Center
Tips
参考: