Count occurrences with grep

Adam K Dean - Jul 4 '14 - - Dev Community

Today I learnt that grep has a '-c' switch that counts occurrences. I'll never pipe it to 'wc -l' again!

$ ps aux | grep -c adam
93
Enter fullscreen mode Exit fullscreen mode

But if we use wc, we would also need to trim it:

$ ps aux | grep adam | wc -l
        94
Enter fullscreen mode Exit fullscreen mode

So, use -c.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player