grepコマンドでカウント数を表示する方法
grepコマンドでカウント数を表示するには-cオプションを指定します。
オプションの説明
-c, --count print only a count of matching lines per FILE
以下のファイルを対象とします。
$ cat test.txt apple,001 apple,002 banana,003 lemon,004 orange,005 strawberry,006
-cオプションを指定した場合
$ grep -c 'apple' test.txt 2 $ grep -c '00' test.txt 6 $ grep -c 'melon' test.txt 0
-cオプションを指定しない場合
$ grep 'apple' test.txt apple,001 apple,002 $ grep '00' test.txt apple,001 apple,002 banana,003 lemon,004 orange,005 strawberry,006 $ grep 'melon' test.txt