LoginSignup
1
0

More than 1 year has passed since last update.

よく使用するgrepオプション

Posted at

個人的によく使用するオプションをメモしておきます。
以下のテストファイルを例で使用します。

test.txt
abc
DEF
GhI
def
オプション 効果 実行結果
-A NUM マッチした行と、その後のNUM行数表示 grep -A 1 "DEF" test.txt DEF
GhI
-B NUM マッチした行と、その前のNUM行数表示 grep -B 1 "DEF" test.txt abc
DEF
-C NUM マッチした行と、その前のNUM行数表示 grep -C 1 "DEF" test.txt abc
DEF
GhI
-c マッチした行数を表示 grep -c "DEF" test.txt 1
-E 正規表現を使用 grep -E "^DE" test.txt DEF
-e or検索 grep -e "DEF" -e "abc" text.txt abc
DEF
-i 大文字と小文字の区別をしない grep -i "DEF" test.txt DEF
def
-n 行数を表示 grep -n "DEF" test.txt 2:DEF
-v マッチしなかった行を表示 grep -v "DEF" test.txt abc
GhI
def

AND検索する際はパイプで繋げる

$ grep -i "DEF" test.txt | grep "def"
def 
1
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
1
0