Double Grep Count

Hi Friends,

I want to find all processes beginning with the name 'Admin' and then do a grep count on those processes containing a specific string i.e. However, it is giving below error

 
ps -ef | grep ^Admin | grep -ic 'Jan' -e 'Feb' -e 'Mar'
 
grep: Jan: No such file or directory

I am able to get the lines themselves by using following command, which is successful. How to get the count of it?

 
ps -ef | grep ^Admin | grep -inae 'Jan' -e 'Feb' -e 'Mar'

Hello srkmish,

Could you please try following and let us know if this helps.

ps -ef | awk '/^dmdadm06/ {if($0 ~ var){count_var++}} END{print count_var}' var="string needs to be searched"

Similarly we can put more conditions in if segment code if number of strings which we need to search are more than 1 in number.

Thanks,
R. Singh

Hi,

You can try the following if you just want a count.

ps -ef | grep ^Admin | grep -inae 'Jan' -e 'Feb' -e 'Mar' | wc -l

Regards

Dave

Thanks Gull and Ravinder, your solution works perfect. However i found another simpler solution.

 
ps -ef | grep ^Admin | egrep -ic 'Jan|Feb|Mar'

Try

ps -ef | grep ^Admin | grep -ice 'Jan' -e 'Feb' -e 'Mar'