LoginSignup
2
2

More than 5 years have passed since last update.

【linuxコマンド】grep

Posted at

grepコマンド

指定したファイルの中から指定した文字列を探すコマンド。
検索文字列やファイルは正規表現で書くことができる。

基本のコマンド

$grep [オプション] [文字列] [ファイル]

test.txtファイル中のaという文字を探す場合は以下のように書く。

$grep a test.txt

オプション

-i 

検索文字の大文字小文字を区別しない。

-f [file] 

検索文字列としてfileの中身を使用する。

-l

検索条件に一致したファイルを表示する。

-c

検索条件に一致した行数を表示する。

-v

検索に一致しなかった行を表示する。
-lvとすると、一致しなかったファイルを表示する。

-w

検索を文字列全体に対して行う。

-x

検索を行全体に対して行う。

2
2
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
2
2