0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Linux][command] テキスト処理_抽出_grep, egrep, fgrep

Last updated at Posted at 2025-04-11

grepコマンド

$ grep [オプション] 検索パターン [ファイル名]
$ grep [オプション] [-f ファイル名] [ファイル名]
オプション 由来 説明
(default) デフォルト 指定したパターンにマッチする行を検索して出力する
-c count マッチした行数を表示する
-f file ファイルから読み込んで検索する(1行1パターン)
-i ignore case 大文字・小文字を区別せずに検索する
-n number マッチした行の行番号を表示する
-v invert match 指定したパターンにマッチしない行を出力する
-r | -R recursive サブディレクトリ内も再帰的に検索する
-E extended 拡張正規表現を使用する(egrepと同等)
-F fixed 正規表現ではなく固定文字列として検索する(fgrepと同等)

egrepコマンド

  • egrep(Extended GREP)は、拡張正規表現(ERE: Extended Regular Expressions)を使って検索するコマンド
  • grep -E と同等
$ egrep [オプション] 検索パターン [ファイル名]

fgrepコマンド

  • fgrep(Fixed-string GREP)は、特殊な正規表現を使用せずに固定文字列を検索するコマンド
  • grep -F と同等
$ fgrep [オプション] 検索パターン [ファイル名]

使用例

grepコマンドの場合

"a" と "b" の間に任意の1文字を含む行を検索

$ grep "a.b" file.txt

egrepコマンドの場合

"a" または "b" を含む行を検索(正規表現の | を使用)

$ egrep "a|b" file.txt

fgrepコマンドの場合

"a.b" という文字列そのままを検索

$ fgrep "a.b" file.txt

Ping-t

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?