Adam K Dean

Count occurrences with grep

Published on 4 July 2014 at 13:02 by Adam

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

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

$ ps aux | grep adam | wc -l
        94

So, use -c.



This post was first published on 4 July 2014 at 13:02. It was filed under archive with tags grep, bash.