USING WC and GREP together

I need to use the "GREP" and "WC" commands on a single line to find out how many accounts are in the same group   /etc/passwd (My own server)...what is the proper syntax to use?
EaglesFanAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
kellyjjConnect With a Mentor Commented:
grep "<group id>" /etc/passwd |wc -l
0
 
ozoCommented:
grep "^[^:]*:[^:]*:[^:]*:$group:" /etc/passwd | wc
0
 
gothickCommented:
You can use the "cut" command as an alternative to that grep syntax -- it can cut out
the group column more easily, then you can pass that to grep/wc.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
bchewCommented:
cut -d: -f3 /etc/passwd | grep <group number> | wc -l
0
 
n0thingCommented:
awk -F: '{print $4}' /etc/passwd | grep <groupid> | wc -l
is another solution
0
 
ozoCommented:
#the above solutions with cut and awk probably want to use grep -x
#or, using neither grep nor wc:
perl -F: -ane '$c+=$F[3]=='«groupid»';END{print "$c\n"}' /etc/passwd
0
 
bchewCommented:
ozo is right about grep -x.  Otherwise, you will be counting groups you didn't intend.  For instance, if you grep for 100 without the -x you would also get groups 1000, 1100, 2100, etc.

0
 
bchewCommented:
kellyjj

First of all, your "answer" won't work (it will give lots of false hits)!  Furthermore, what you propose is as an has already presented by others as comments!  I believe this is a blatant attempt to "steal" unearned points rather than try to help someone with a solution to their problem.
0
 
braveheartCommented:
I reckon you should use nawk:

nawk -F: '{groups[$4]++}\\
END      {for (grp in groups) print grp, groups[grp]}' \
/etc/passwd

This will list two columns - the first contains the number of occurences of the group and the second contains the group id.
0
 
braveheartCommented:
Take it easy.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.