grepでヒットした行数を表示する方法をメモしておきます。
grep -c
を使う
grepコマンドに-c
オプションをつけるだけでOKです。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 適当なファイルを用意する | |
$ cat hoge.log | |
ERROR | |
WARN | |
INFO | |
ERROR | |
ERROR | |
# grepでヒットした行数を表示する | |
$ grep -c ERROR hoge.log | |
3 |
まとめ
grepでヒットした行数を表示する方法でした。