Double Grep Count


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Double Grep Count
# 1  
Old 11-04-2014
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

Code:
 
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?

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

# 2  
Old 11-04-2014
Hello srkmish,

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

Code:
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
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 11-04-2014
Hi,

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

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

Regards

Dave
This User Gave Thanks to gull04 For This Post:
# 4  
Old 11-04-2014
Thanks Gull and Ravinder, your solution works perfect. However i found another simpler solution.

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

# 5  
Old 11-04-2014
Try
Code:
ps -ef | grep ^Admin | grep -ice 'Jan' -e 'Feb' -e 'Mar'

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exact grep and count

got a file as y.txt 1 abc,def,ghj 2 defj,abc.kdm,ijk 3 lmn,cbk,mno 4 tmp,tmop,abc,pkl 5 pri,chk,cbk,lmo 6 def,cbk.pro,abc.kdm i want to search in the above file the key word like abc looking for two outcomes by passing the parameter value as abc into function and the two outocmes are... (0 Replies)
Discussion started by: silgun
0 Replies

2. UNIX for Dummies Questions & Answers

Grep and Count Duplicates

I have a delimited file (by |), and the second field is made out of Surnames. Is it possible to list the surnames together with their count of occurances. For example, image the first two lines are the following: Joe | Doe | 30 Jane | Doe | 28 Peter | Smith | 25 John | Jones | 26 I... (2 Replies)
Discussion started by: mouthpiec
2 Replies

3. Shell Programming and Scripting

How to count number of double quotes in bash

Need a little help. I have just a simple string with a lot double quotes in it. I need to be able to parse through this string, and know how many double quotes I have, and where I am, so I can key off every 9th double quote. For example (coding is not complete): #!/bin/bash count=0... (3 Replies)
Discussion started by: Akilleez
3 Replies

4. Shell Programming and Scripting

how to find the count of commas in a string excluding the ones in double quotes

Hi, my requirement is to find the count of commas in a string excluding the ones in double quotes. For example: If the input string is abc,xyz.com,lmhgdf,"abc, 401 street","tty,stt",45,23,45 The output should be 7 (7 Replies)
Discussion started by: amitshete
7 Replies

5. UNIX for Dummies Questions & Answers

Grep group by and count

Hi, I have several files with same filename pattern. I want to calculate count of individual files using grep/egrep. Let me be more descriptive In directory E1 i have files like ab_20091201_12:24 ab_20091201_03:24 cd_20091201_04:16 cd_20091203_08:34 ef_20091201_06:12 ef_20091201 Now i want... (3 Replies)
Discussion started by: shounakboss
3 Replies

6. UNIX for Dummies Questions & Answers

Sorting using count, grep and count

Hi, I trying to sort information in a file by making count for every object. For example: A B A D A B C i would like to sort out count for each object (A's, B's and etc) but in actual case i dont know the object but i know the position ofthe object. do i need to use array as well? Any... (2 Replies)
Discussion started by: sukhpal_78
2 Replies

7. UNIX for Dummies Questions & Answers

to grep and find the count

Hi My files is like a|test|s| b|test2 | n| c|ggg|v| i want to count the no of lines which is ending with "|" ... Please let me know how can it be done. Thanks, Arun (4 Replies)
Discussion started by: arunkumar_mca
4 Replies

8. UNIX for Dummies Questions & Answers

count on the grep

The following command lists the files which has "wPOREQ" in the files whose names are like:M*08042007* grep -l "aaa" M*08042007* I want to know the count of the files. Thank you for the help. (2 Replies)
Discussion started by: sudheshnaiyer
2 Replies

9. UNIX for Dummies Questions & Answers

Grep with count

I need to count the number of instances of a dir in a set of dir with the same suffix .txt (one dir and all recursive directories). <Main Dir> <sub_dir1> <sub_dir2> <sub_dir3> <sub_dir4> and count the number of instances of a type of file, ie/ .txt files (3 Replies)
Discussion started by: t4st33@mac.com
3 Replies
Login or Register to Ask a Question