61
44

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【linux】grepで前後の数行も取得する【コマンド】

Last updated at Posted at 2017-09-02

すぐ忘れるのでメモ:pencil2:

grepコマンドの-numオプション

# grep -3 "test"

「-3」を付けることで、検索文字列"test"の前後3行も表示します。
数字の部分を入れ替えれば、好きな行数が取得できます。
エラーログなんかは、前後数行が見れるだけでも違いますよね:sweat_drops:

前のn行が欲しい時

# grep -B 3 "test"

-B」で前のn行を取得できます。
※上記サンプルでは3行

後ろのn行が欲しい時

# grep -A 5 "test"

-A」で後ろのn行を取得できます。
※上記サンプルでは5行

61
44
1

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
61
44

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?